|
|
# yhcxglxt
|
|
|
|
|
|
学生信息管理系统源程序清单:
|
|
|
//StuMange.java程序清单
|
|
|
package keshe;
|
|
|
import java.awt.BorderLayout;
|
|
|
import java.awt.Panel;
|
|
|
import java.awt.event.ActionEvent;
|
|
|
import java.awt.event.ActionListener;
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.DriverManager;
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
import javax.swing.JButton;
|
|
|
import javax.swing.JFrame;
|
|
|
import javax.swing.JLabel;
|
|
|
import javax.swing.JOptionPane;
|
|
|
import javax.swing.JScrollPane;
|
|
|
import javax.swing.JTable;
|
|
|
import javax.swing.JTextField;
|
|
|
|
|
|
public class StuMange extends JFrame implements ActionListener{
|
|
|
//定义用户界面用到的组件
|
|
|
JLabel userName = null; //要查询的学生的名字
|
|
|
JTextField textField = null; //用户输入的文本框
|
|
|
JButton select = null; //查询按钮
|
|
|
JButton insert = null; //添加按钮
|
|
|
JButton update = null; //修改按钮
|
|
|
JButton delete = null; //删除按钮
|
|
|
JTable table = null; //用于显示数据库调出的数据的表
|
|
|
Panel panel1 = null;
|
|
|
Panel panel2 = null;
|
|
|
Panel panel3 = null;
|
|
|
JScrollPane jscrollPane = null;
|
|
|
|
|
|
StModel stModel = null; //st表的模型
|
|
|
private Object PreparedStatement;
|
|
|
public StuMange()
|
|
|
{
|
|
|
//窗口显示的上部的组件
|
|
|
userName = new JLabel("学生名:");
|
|
|
textField = new JTextField(10); //用户输入文本框限定为最多输入10个字符
|
|
|
select = new JButton("查询"); //查询按钮
|
|
|
//添加到第一个面板中
|
|
|
panel1 = new Panel();
|
|
|
panel1.add(userName);
|
|
|
panel1.add(textField);
|
|
|
panel1.add(select);
|
|
|
|
|
|
//窗口下部的组件
|
|
|
insert = new JButton("添加");
|
|
|
delete = new JButton("删除");
|
|
|
update = new JButton("修改");
|
|
|
//添加到第三个个面板中
|
|
|
panel3 = new Panel();
|
|
|
panel3.add(insert);
|
|
|
panel3.add(delete);
|
|
|
panel3.add(update);
|
|
|
|
|
|
//窗口中部的组件
|
|
|
stModel = new StModel();
|
|
|
stModel.insertDatabase("select * from st");
|
|
|
table = new JTable(stModel);
|
|
|
jscrollPane = new JScrollPane(table);
|
|
|
|
|
|
//注册事件监听
|
|
|
select.addActionListener(this);
|
|
|
insert.addActionListener(this);
|
|
|
update.addActionListener(this);
|
|
|
delete.addActionListener(this);
|
|
|
|
|
|
|
|
|
//将各个组件添加到窗体中
|
|
|
this.add(panel1, BorderLayout.NORTH);
|
|
|
this.add(jscrollPane, BorderLayout.CENTER);
|
|
|
this.add(panel3, BorderLayout.SOUTH);
|
|
|
|
|
|
//设置窗体属性
|
|
|
this.setSize(400, 300); //设置窗口大小
|
|
|
this.setLocation(200, 200); //设置窗口显示的位置
|
|
|
this.setTitle("学生信息管理系统"); //设置窗口标题
|
|
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //设置窗口关闭之后其后台程序同时关闭
|
|
|
//设置窗口为可见
|
|
|
this.setVisible(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
public void actionPerformed(ActionEvent e)
|
|
|
{
|
|
|
//用户点击了查找按钮
|
|
|
if(e.getSource() == select)
|
|
|
{
|
|
|
String paras = textField.getText().trim();
|
|
|
stModel = new StModel();
|
|
|
stModel.insertDatabase("select * from st where stNname='"+paras+"'");
|
|
|
table.setModel(stModel);
|
|
|
}
|
|
|
//用户点击了添加按钮
|
|
|
else if(e.getSource() == insert)
|
|
|
{
|
|
|
InsertStudent insertStudent = new InsertStudent(this, "添加学生", true);
|
|
|
|
|
|
//刷新窗口表的数据
|
|
|
stModel = new StModel();
|
|
|
stModel.insertDatabase("select * from st");
|
|
|
table.setModel(stModel);
|
|
|
}
|
|
|
//用户点击了修改按钮
|
|
|
else if(e.getSource() == update)
|
|
|
{
|
|
|
int row = this.table.getSelectedRow(); //用户选择的行数
|
|
|
if(-1 == row) //如果用户没有选中行
|
|
|
{
|
|
|
JOptionPane.showMessageDialog(this, "请选择一行");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
UpdateDatabase updateDatabase = new UpdateDatabase(this, "修改学生", true, stModel, row);
|
|
|
//刷新窗口表的数据
|
|
|
stModel =new StModel();
|
|
|
stModel.insertDatabase("select * from st");
|
|
|
table.setModel(stModel);
|
|
|
}
|
|
|
}
|
|
|
//用户点击了删除按钮
|
|
|
else if(e.getSource() == delete)
|
|
|
{
|
|
|
//数据库
|
|
|
Connection con = null;
|
|
|
PreparedStatement ps = null;
|
|
|
String driver = "com.mysql.jdbc.Driver"; //jdbc驱动
|
|
|
String url = "jdbc:mysql://localhost:3306/student"; //数据源
|
|
|
String user = "root"; //数据库用户密码
|
|
|
String passWord = "root"; //数据库用户sa的密码
|
|
|
|
|
|
int row = this.table.getSelectedRow(); //用户选择的行
|
|
|
if(-1 == row) //用户没有选中行
|
|
|
{
|
|
|
JOptionPane.showMessageDialog(this, "请选择一行");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
//加载jdbc驱动
|
|
|
Class.forName(driver);
|
|
|
//连接数据源
|
|
|
con = DriverManager.getConnection(url, user, passWord);
|
|
|
//执行sql
|
|
|
String sql = "delete from st where stId=?";
|
|
|
String id = (String)(stModel.getValueAt(row, 0)); //获得用户选择的行的学生的学号
|
|
|
ps = con.prepareStatement(sql);
|
|
|
ps.setString(1, id);
|
|
|
ps.executeUpdate();
|
|
|
|
|
|
//刷新窗口
|
|
|
stModel = new StModel();
|
|
|
stModel.insertDatabase("select * from st");
|
|
|
table.setModel(stModel);
|
|
|
|
|
|
}
|
|
|
catch(ClassNotFoundException e1)
|
|
|
{
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
catch(SQLException e1)
|
|
|
{
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
//关闭资源
|
|
|
try
|
|
|
{
|
|
|
if(null != ps)
|
|
|
{
|
|
|
ps.close();
|
|
|
}
|
|
|
if(null != con)
|
|
|
{
|
|
|
con.close();
|
|
|
}
|
|
|
}
|
|
|
catch(SQLException e1)
|
|
|
{
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
//StModel.java源程序清单
|
|
|
package keshe;
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.DriverManager;
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
import java.util.Vector;
|
|
|
|
|
|
import javax.swing.table.AbstractTableModel;
|
|
|
|
|
|
public class StModel extends AbstractTableModel{
|
|
|
Vector<String> columNames = null; //表的字段名称
|
|
|
Vector<Vector> rowDate = null; //表的数据
|
|
|
|
|
|
//数据库
|
|
|
private Connection con = null;
|
|
|
private PreparedStatement ps = null;
|
|
|
private ResultSet rs = null;
|
|
|
private final static String driver = "com.mysql.jdbc.Driver"; //加载的jdbc驱动
|
|
|
private final static String url = "jdbc:mysql://localhost:3306/student"; //数据源
|
|
|
private final static String user = "root"; //数据库的用户名
|
|
|
private final static String passWord = "root"; //数据库的用户名的密码
|
|
|
|
|
|
//对数据库进行查找
|
|
|
public void insertDatabase(String sql)
|
|
|
{
|
|
|
columNames = new Vector<String>(); //表的字段名称
|
|
|
rowDate = new Vector<Vector>(); //表的数据
|
|
|
|
|
|
columNames.add("学号");
|
|
|
columNames.add("名字");
|
|
|
columNames.add("性别");
|
|
|
columNames.add("年龄");
|
|
|
columNames.add("籍贯");
|
|
|
columNames.add("系别");
|
|
|
|
|
|
try
|
|
|
{
|
|
|
//加载jdbc驱动
|
|
|
Class.forName(driver);
|
|
|
//连接数据源
|
|
|
con = DriverManager.getConnection(url,user,passWord);
|
|
|
//执行sql
|
|
|
ps = con.prepareStatement(sql);
|
|
|
rs = ps.executeQuery();
|
|
|
while(rs.next())
|
|
|
{
|
|
|
Vector<String> row = new Vector<String>();
|
|
|
row.add(rs.getString(1));
|
|
|
row.add(rs.getString(2));
|
|
|
row.add(rs.getString(3));
|
|
|
row.add(rs.getString(4));
|
|
|
row.add(rs.getString(5));
|
|
|
row.add(rs.getString(6));
|
|
|
|
|
|
rowDate.add(row); //将学生的一条记录(row)添加到rowDate中
|
|
|
}
|
|
|
}
|
|
|
catch(ClassNotFoundException e)
|
|
|
{
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
catch(SQLException e)
|
|
|
{
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
//关闭数据库资源
|
|
|
try
|
|
|
{
|
|
|
if(null != rs)
|
|
|
{
|
|
|
rs.close();
|
|
|
}
|
|
|
if(null != ps)
|
|
|
{
|
|
|
ps.close();
|
|
|
}
|
|
|
if(null != con)
|
|
|
{
|
|
|
con.close();
|
|
|
}
|
|
|
}
|
|
|
catch(SQLException e)
|
|
|
{
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
//返回列数
|
|
|
public int getColumnCount() {
|
|
|
return this.columNames.size();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
//返回表的行数
|
|
|
public int getRowCount() {
|
|
|
return this.rowDate.size();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
//得到某行某列的数据
|
|
|
public Object getValueAt(int rowIndex, int columnIndex) {
|
|
|
return ((Vector)this.rowDate.get(rowIndex)).get(columnIndex);
|
|
|
}
|
|
|
//设置表的字段名
|
|
|
public String getColumnName(int column)
|
|
|
{
|
|
|
return (String)this.columNames.get(column);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//---------------------------------------------------------------------------------------------------------
|
|
|
//Mannager.java源程序清单
|
|
|
package keshe;
|
|
|
|
|
|
public class Mannager {
|
|
|
public static void main(String[] agrgs){
|
|
|
StuMange sm = new StuMange();
|
|
|
}
|
|
|
}
|
|
|
//-----------------------------------------------------------------------------------------------------------
|
|
|
//InsertStudent.java源程序清单
|
|
|
package keshe;
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
|
import java.awt.Frame;
|
|
|
import java.awt.GridLayout;
|
|
|
import java.awt.Panel;
|
|
|
import java.awt.event.ActionEvent;
|
|
|
import java.awt.event.ActionListener;
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.DriverManager;
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
import javax.swing.JButton;
|
|
|
import javax.swing.JDialog;
|
|
|
import javax.swing.JLabel;
|
|
|
import javax.swing.JOptionPane;
|
|
|
import javax.swing.JTextField;
|
|
|
|
|
|
public class InsertStudent extends JDialog implements ActionListener{
|
|
|
private JLabel id, name, sex, age, address, dep; //分别代表学生的学号,名字,性别,年龄,籍贯,系别
|
|
|
private JTextField jtf1, jtf2, jtf3, jtf4, jtf5, jtf6; //用户输入的文本框,分别为学生的学号,名字,性别,年龄,籍贯,系别
|
|
|
private JButton add, canel; //分别为添加按钮和取消按钮
|
|
|
private Panel panel1, panel2, panel3;
|
|
|
|
|
|
public InsertStudent(Frame owner, String title, boolean model)
|
|
|
{
|
|
|
super(owner, title, model); //实现与父类窗口对话
|
|
|
System.out.println("我执行了");
|
|
|
|
|
|
//窗体的西部的组件
|
|
|
id = new JLabel("学号:");
|
|
|
name = new JLabel("姓名:");
|
|
|
sex = new JLabel("性别");
|
|
|
age = new JLabel("年龄");
|
|
|
address = new JLabel("籍贯");
|
|
|
dep = new JLabel("系别:");
|
|
|
//添加到panel1面板中
|
|
|
panel1 = new Panel(new GridLayout(6, 1));
|
|
|
panel1.add(id);
|
|
|
panel1.add(name);
|
|
|
panel1.add(sex);
|
|
|
panel1.add(age);
|
|
|
panel1.add(address);
|
|
|
panel1.add(dep);
|
|
|
|
|
|
//窗体的东部组件
|
|
|
jtf1 = new JTextField(10);
|
|
|
jtf2 = new JTextField(10);
|
|
|
jtf3 = new JTextField(10);
|
|
|
jtf4 = new JTextField(10);
|
|
|
jtf5 = new JTextField(10);
|
|
|
jtf6 = new JTextField(10);
|
|
|
//添加到第二个面板中
|
|
|
panel2 = new Panel(new GridLayout(6, 1));
|
|
|
panel2.add(jtf1);
|
|
|
panel2.add(jtf2);
|
|
|
panel2.add(jtf3);
|
|
|
panel2.add(jtf4);
|
|
|
panel2.add(jtf5);
|
|
|
panel2.add(jtf6);
|
|
|
|
|
|
//窗体北部的控件
|
|
|
add = new JButton("添加");
|
|
|
canel = new JButton("取消");
|
|
|
|
|
|
//注册事件监听
|
|
|
add.addActionListener(this);
|
|
|
canel.addActionListener(this);
|
|
|
|
|
|
//添加到panel3面板中
|
|
|
panel3 = new Panel();
|
|
|
panel3.add(add);
|
|
|
panel3.add(canel);
|
|
|
|
|
|
//将各个组件添加到窗体中
|
|
|
this.add(panel1, BorderLayout.WEST);
|
|
|
this.add(panel2, BorderLayout.CENTER);
|
|
|
this.add(panel3, BorderLayout.SOUTH);
|
|
|
|
|
|
//设置对话框属性
|
|
|
this.setSize(300, 200);
|
|
|
//设置对话框为可见
|
|
|
this.setVisible(true);
|
|
|
}
|
|
|
|
|
|
|
|
|
public void actionPerformed(ActionEvent e)
|
|
|
{
|
|
|
//数据库
|
|
|
Connection con = null;
|
|
|
PreparedStatement ps = null;
|
|
|
|
|
|
boolean result = true; //记录添加学生是否成功
|
|
|
|
|
|
if(e.getSource() == add)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
//加载jdbc驱动
|
|
|
Class.forName("com.mysql.jdbc.Driver");
|
|
|
//连接数据源
|
|
|
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/student", "root", "root");
|
|
|
//执行sql
|
|
|
String sql = "insert into st values(?,?,?,?,?,?)";
|
|
|
ps = con.prepareStatement(sql);
|
|
|
|
|
|
ps.setString(1, jtf1.getText());
|
|
|
ps.setString(2, jtf2.getText());
|
|
|
ps.setString(3, jtf3.getText());
|
|
|
ps.setString(4, jtf4.getText());
|
|
|
ps.setString(5, jtf5.getText());
|
|
|
ps.setString(6, jtf6.getText());
|
|
|
|
|
|
ps.executeUpdate();
|
|
|
|
|
|
//关闭对话框
|
|
|
this.dispose();
|
|
|
}
|
|
|
catch(ClassNotFoundException e1)
|
|
|
{
|
|
|
result = false; //添加学生记录失败
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
catch(SQLException e1)
|
|
|
{
|
|
|
result = false; //添加学生记录失败
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
//关闭资源
|
|
|
try
|
|
|
{
|
|
|
if(null != ps)
|
|
|
{
|
|
|
ps.close();
|
|
|
}
|
|
|
if(null != con)
|
|
|
{
|
|
|
con.close();
|
|
|
}
|
|
|
}
|
|
|
catch(SQLException e1)
|
|
|
{
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(false == result)
|
|
|
{
|
|
|
JOptionPane.showMessageDialog(this, "失败信息:学号不能重复,性别只能为'男'或者'女',年龄大于0");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
else if(e.getSource() == canel)
|
|
|
{
|
|
|
//关闭对话框
|
|
|
this.dispose();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//---------------------------------------------------------------------------------------------------------
|
|
|
//UpdateDatabase.java源程序清单
|
|
|
package keshe;
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
|
import java.awt.Frame;
|
|
|
import java.awt.GridLayout;
|
|
|
import java.awt.Panel;
|
|
|
import java.awt.event.ActionEvent;
|
|
|
import java.awt.event.ActionListener;
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.DriverManager;
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
import javax.swing.JButton;
|
|
|
import javax.swing.JDialog;
|
|
|
import javax.swing.JLabel;
|
|
|
import javax.swing.JOptionPane;
|
|
|
import javax.swing.JTextField;
|
|
|
|
|
|
public class UpdateDatabase extends JDialog implements ActionListener{
|
|
|
JLabel id,name,sex,age,address,dep; //分别为学生的学号,学生的姓名,学生的性别,学生的年龄,学生的籍贯,学生的系别的标签
|
|
|
JTextField jtf1, jtf2, jtf3, jtf4,jtf5, jtf6; //分别为学生的学号,姓名,性别,年龄,籍贯,系列的输入文本框
|
|
|
JButton update,canel; //分别为修改和取消按钮
|
|
|
Panel panel1 ,panel2, panel3;
|
|
|
|
|
|
public UpdateDatabase(Frame own, String title, boolean model, StModel stModel, int row)
|
|
|
{
|
|
|
super(own, title, model); //实现与父类窗口对话
|
|
|
|
|
|
//窗体西部的组件
|
|
|
id = new JLabel("学号");
|
|
|
name = new JLabel("名字");
|
|
|
sex = new JLabel("性别");
|
|
|
age = new JLabel("年龄");
|
|
|
address = new JLabel("地址");
|
|
|
dep = new JLabel("系别");
|
|
|
//添加到panel1中
|
|
|
panel1 = new Panel(new GridLayout(6, 1));
|
|
|
panel1.add(id);
|
|
|
panel1.add(name);
|
|
|
panel1.add(sex);
|
|
|
panel1.add(age);
|
|
|
panel1.add(address);
|
|
|
panel1.add(dep);
|
|
|
|
|
|
//添加到窗体的东部的组件
|
|
|
jtf1 = new JTextField(10);
|
|
|
jtf1.setText((String)(stModel.getValueAt(row, 0)));
|
|
|
jtf1.setEditable(false);//设置学号不可修改
|
|
|
jtf2 = new JTextField(10);
|
|
|
jtf2.setText((String)(stModel.getValueAt(row, 1)));
|
|
|
jtf3 = new JTextField(10);
|
|
|
jtf3.setText((String)(stModel.getValueAt(row, 2)));
|
|
|
jtf4 = new JTextField(10);
|
|
|
jtf4.setText((String)(stModel.getValueAt(row, 3)));
|
|
|
jtf5 = new JTextField(10);
|
|
|
jtf5.setText((String)(stModel.getValueAt(row, 4)));
|
|
|
jtf6 = new JTextField(10);
|
|
|
jtf6.setText((String)(stModel.getValueAt(row, 5)));
|
|
|
//添加到第二个面板中
|
|
|
panel2 = new Panel(new GridLayout(6, 1));
|
|
|
panel2.add(jtf1);
|
|
|
panel2.add(jtf2);
|
|
|
panel2.add(jtf3);
|
|
|
panel2.add(jtf4);
|
|
|
panel2.add(jtf5);
|
|
|
panel2.add(jtf6);
|
|
|
|
|
|
//窗体南部的组件
|
|
|
update = new JButton("确认");
|
|
|
canel = new JButton("取消");
|
|
|
panel3 = new Panel();
|
|
|
panel3.add(update);
|
|
|
panel3.add(canel);
|
|
|
|
|
|
//注册事件监听
|
|
|
update.addActionListener(this);
|
|
|
canel.addActionListener(this);
|
|
|
|
|
|
//添加组件到窗体中
|
|
|
this.add(panel1, BorderLayout.WEST);
|
|
|
this.add(panel2, BorderLayout.CENTER);
|
|
|
this.add(panel3, BorderLayout.SOUTH);
|
|
|
|
|
|
//设置窗体属性
|
|
|
this.setSize(300, 200);
|
|
|
//设置窗体为可见
|
|
|
this.setVisible(true);
|
|
|
}
|
|
|
|
|
|
//响应用户操作
|
|
|
public void actionPerformed(ActionEvent e)
|
|
|
{
|
|
|
//数据库
|
|
|
Connection con = null;
|
|
|
PreparedStatement ps = null;
|
|
|
String driver = "com.mysql.jdbc.Driver"; //jdbc驱动
|
|
|
String url = "jdbc:mysql://localhost:3306/student"; //连接数据源
|
|
|
String user = "root"; //数据库的用户
|
|
|
String passWord = "root"; //数据库的用户密码
|
|
|
boolean result = true; //记录修改学生是否成功
|
|
|
|
|
|
if(e.getSource() == update)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
//加载jdbc驱动
|
|
|
Class.forName(driver);
|
|
|
//连接数据源
|
|
|
con = DriverManager.getConnection(url,user,passWord);
|
|
|
//执行sql
|
|
|
String sql = "update st set stNname=?, stSex=?,stAge=?,stBorn=?,stDept=? where stId=? ";
|
|
|
ps = con.prepareStatement(sql);
|
|
|
//修改学生数据
|
|
|
ps.setString(1, jtf2.getText());
|
|
|
ps.setString(2, jtf3.getText());
|
|
|
ps.setString(3, jtf4.getText());
|
|
|
ps.setString(4, jtf5.getText());
|
|
|
ps.setString(5, jtf6.getText());
|
|
|
ps.setString(6, jtf1.getText());
|
|
|
|
|
|
ps.executeUpdate();
|
|
|
//关闭对话框
|
|
|
this.dispose();
|
|
|
}
|
|
|
catch(ClassNotFoundException e1)
|
|
|
{
|
|
|
result = false;
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
catch(SQLException e1)
|
|
|
{
|
|
|
result = false;
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
//关闭资源
|
|
|
try
|
|
|
{
|
|
|
if(null != ps)
|
|
|
{
|
|
|
ps.close();
|
|
|
}
|
|
|
if(null != con)
|
|
|
{
|
|
|
con.close();
|
|
|
}
|
|
|
}
|
|
|
catch(SQLException e1)
|
|
|
{
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
if(false == result)
|
|
|
{
|
|
|
JOptionPane.showMessageDialog(this, "失败信息:学号不能重复,性别只能为'男'或者'女',年龄大于0");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
else if(e.getSource() == canel)
|
|
|
{
|
|
|
this.dispose();//关闭对话框
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|