// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false); show(); }
CM(CSelect cst, String title) {// 构造方法 super(title); this.cst = cst; bstd = true; add(\ this.add(\ mb.add(btnAdd); mb.add(btnDelete); mb.add(btnAlter); mb.add(btnSearch); mb.add(btnDisplay); this.connDB(); this.setBounds(200, 200, 400, 260); btnAdd.addActionListener(this); btnDelete.addActionListener(this); btnAlter.addActionListener(this); btnSearch.addActionListener(this); btnDisplay.addActionListener(this); this.setJMenuBar(mb); // this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false); show(); }
public void display() {// 显示所有的课程信息 int i = 0; int j = 0; int k = 0; List al = new ArrayList(); try { rs = stmt.executeQuery(\ while (rs.next()) {// 找出表中的记录数赋给i al.add(rs.getString(\ al.add(rs.getString(\ al.add(rs.getString(\ i++; }
} catch (SQLException e) { e.printStackTrace(); } playerInfo = new Object[i][3]; String[] columnNames = { \课程号\课程名\先行课程号\ try { rs = stmt.executeQuery(\ while (rs.next()) { playerInfo[j][0] = rs.getString(\ playerInfo[j][1] = rs.getString(\ playerInfo[j][2] = rs.getString(\ j++; } } catch (SQLException e) { e.printStackTrace(); } sTable = new JTable(playerInfo, columnNames);// 创建网格 p1.add(sTable); scroll = new JScrollPane(sTable); this.add(scroll); }
public void connDB() { // 连接数据库 try { Class.forName(\ } catch (ClassNotFoundException e) { e.printStackTrace(); } try { con = DriverManager.getConnection( \ \ stmt = con.createStatement(); } catch (SQLException e) { e.printStackTrace(); } }
public void closeDB() // 关闭连接 { try { stmt.close();
con.close(); } catch (SQLException e) { e.printStackTrace(); } }
public void delete() {// 删除某个课程信息 String kch = null; String kcm = null; String xxkch = null; int row = -1; row = sTable.getSelectedRow(); if (row == -1) {// 判断要删除的信息是否被选中 JOptionPane.showMessageDialog(null, \请选择要删除的记录!\ } else { if (!bstd) {// 判断选择的是不是查询后的结果 int j1 = 0; try { rs = stmt.executeQuery(\ while (rs.next() && j1 <= row) {// 找出当前被选中的记录在数据库中的对应 kch = rs.getString(\ kcm = rs.getString(\ xxkch = rs.getString(\ j1++; } } catch (SQLException e) { e.printStackTrace(); } int i1 = 0; try { int rs1 = stmt.executeUpdate(\ + kch + \删除数据库中当前被选中的记录 JOptionPane.showMessageDialog(null, \记录删除成功!\ this.dispose(); new CM(\课程信息管理\ } catch (SQLException e) { e.printStackTrace(); } } else { try { int rs1 = stmt.executeUpdate(\
+ mkch + \删除数据库中当前被选中的记录 JOptionPane.showMessageDialog(null, \记录删除成功!\ this.dispose(); new CM(\课程信息管理\ } catch (SQLException e) { e.printStackTrace(); } } } }
public void update() {// 修改某个课程记录 String kch = null; String kcm = null; String xxkch = null; int row = -1; row = sTable.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(null, \请选择要修改的记录!\ } else { int j1 = 0; try { if (!bstd) {// 判断选择的是不是查询后的结果 rs = stmt.executeQuery(\ } else { rs = stmt.executeQuery(\ + \ } while (rs.next() && j1 <= row) {// 找出当前被选中的记录在数据库中的对应 kch = rs.getString(\ kcm = rs.getString(\ xxkch = rs.getString(\ j1++; } } catch (SQLException e) { e.printStackTrace(); } CAdd cadd = new CAdd(); cadd.setTitle(\修改\ cadd.tcno.setText(kch); cadd.tcname.setText(kcm);
相关推荐: