⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 insertinfo.java

📁 简单的学生管理系统
💻 JAVA
字号:
package catking.home.love;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.swing.JOptionPane;


public class InsertInfo extends EditClientInfo{
	private Connection con;
	public InsertInfo(Connection con,String title,String EditInfo)
	{
		super(title,EditInfo);
		this.con = con;
		
	}
	@Override
	protected void isConfirm() {
		// TODO Auto-generated method stub
		//检测是否有空值
		for(int i =0; i < tf.length; ++i)
		{
			if(tf[i].getText().equals(""))
			{
				JOptionPane.showMessageDialog(null, 
						"输入错误", this.itemNames[i] + "栏不能为空",
							 JOptionPane.ERROR_MESSAGE);
				return;
			}
		}
		//尝试插入操作
		// id 	name	sex		dept
		String[] strInfo = new String[4];
		int age;
		String sqlAppend = "INSERT INTO S(SNO,SN,SEX,DEPT,AGE)VALUES(?,?,?,?,?)";
		try {
			PreparedStatement ps = con.prepareStatement(sqlAppend);
			for(int i =0; i < strInfo.length; ++i)
			{
				strInfo[i] = this.tf[i].getText();
				ps.setString(i + 1 ,strInfo[i]);
			}
			age = Integer.parseInt(this.tf[4].getText());
			ps.setInt(5,age);
			//添加
			ps.executeUpdate();
			JOptionPane.showMessageDialog(null, 
					"添加成功", "您插入记录已经成功了!",
						 JOptionPane.PLAIN_MESSAGE);
			//关闭ps
			ps.close();
			
		} catch (SQLException e) {
			
			JOptionPane.showMessageDialog(null, 
					"输入错误", "对不起,添加数据失败!",
						 JOptionPane.ERROR_MESSAGE);
		}
		
		
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -