JTextField tcname = new JTextField(10);
JTextField tpcno = new JTextField(10);
JButton btnOK = new JButton("确定”);
JButton btnCancel = new JButton(”取消”);
JPanel p = new JPanel();
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
boolean isNewsm = true;// 用于判断是否显示课程信息管理的界面
public CAdd() {// 构造方法
this。setTitle("增加");
this。setBounds(200, 200, 146, 235);
p。setLayout(new FlowLayout(FlowLayout.LEFT));
p。add(lcno);
p.add(tcno);
p。add(lcname);
p.add(tcname);
p。add(lpcno);
p.add(tpcno);
p.add(btnOK);
p.add(btnCancel);
this。add(p);
this。setResizable(false);
this.setDefaultCloseOperation(JFrame。EXIT_ON_CLOSE);
btnOK。addActionListener(this);
btnCancel。addActionListener(this);
this。show();
}
public void connDB() { // 连接数据库
try {
Class.forName("com.microsoft。sqlserver。jdbc.SQLServerDriver”);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
con = DriverManager。getConnection(
"jdbc:sqlserver://localhost:1433; DatabaseName=student",
"sa", ”123");
stmt = con.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void closeDB() // 关闭连接
评论0
最新资源