📄 frame2.java
字号:
package untitled2;import javax.swing.*;import java.awt.*;import com.borland.jbcl.layout.*;import com.borland.dx.sql.dataset.*;import java.awt.event.*;import java.sql.*;//教师基本信息查询/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2006</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class Frame2 extends JFrame { JComboBox jComboBox1 = new JComboBox(); XYLayout xYLayout1 = new XYLayout(); JLabel jLabel1 = new JLabel(); JButton jButton1 = new JButton(); JLabel jLabel2 = new JLabel(); JTextField jTextField1 = new JTextField(); JButton jButton2 = new JButton(); JScrollPane jScrollPane1 = new JScrollPane();// JTable jTable1 = new JTable(); JLabel jLabel3 = new JLabel(); Database database1 = new Database(); Object columnnames1[] = { "教师编号", "教师部门编号","教师类型","教师名字", "教师性别","教师联系电话", "教师状态", "教师生日" }; Object rowdata1[][] = new Object[14][9]; JTable jTable1 = new JTable(rowdata1, columnnames1); PreparedStatement ps; ResultSet rs; String sql=null; public Frame2() { try { jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } void jbInit() throws Exception { this.getContentPane().setLayout(xYLayout1); jLabel1.setText("选择"); jButton1.setText("查询"); jButton1.addActionListener(new Frame2_jButton1_actionAdapter(this)); xYLayout1.setWidth(728); xYLayout1.setHeight(382); jLabel2.setText("条件"); jTextField1.setText(""); jButton2.setText("重新查询"); jButton2.addActionListener(new Frame2_jButton2_actionAdapter(this)); jLabel3.setText("查询结果:"); // jLabel4.setText("jLabel4"); database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:odbc:Digital_Campus", "dbw", "123456", false, "sun.jdbc.odbc.JdbcOdbcDriver")); this.setName("frame0"); this.setResizable(false); this.setSize(new Dimension(800, 600)); this.getContentPane().add(jLabel1, new XYConstraints(9, 19, 71, 26)); this.getContentPane().add(jComboBox1, new XYConstraints(40, 17, 94, 28)); this.getContentPane().add(jLabel2, new XYConstraints(144, 18, 66, 31)); this.getContentPane().add(jTextField1, new XYConstraints(185, 19, 97, 25)); this.getContentPane().add(jButton1, new XYConstraints(296, 17, 59, 28)); this.getContentPane().add(jButton2, new XYConstraints(371, 17, 92, 31)); this.getContentPane().add(jScrollPane1, new XYConstraints(1, 92, 727, 258)); this.getContentPane().add(jLabel3, new XYConstraints(4, 49, -1, 34)); jScrollPane1.getViewport().add(jTable1, null); jComboBox1.addItem("全部"); jComboBox1.addItem("教师编号"); jComboBox1.addItem("教师名字"); jComboBox1.addItem("教师部门编号"); jComboBox1.addItem("教师性别"); jComboBox1.addItem("教师类型"); jComboBox1.addItem("教师状态"); //jComboBox1.addItem("教师学历");//"教师编号", "教师名字", "教师部门编号", "教师性别", "教师类型", "教师状态", "教师生日", "教师学历", "教师联系电话" } void jButton2_actionPerformed(ActionEvent e) { jTextField1.setText(""); for (int j = 0; j < rowdata1.length; j++) { for (int k = 0; k < 9; k++) rowdata1[j][k] = null; } jTable1.repaint(); } void jButton1_actionPerformed(ActionEvent e) throws SQLException { String st=jTextField1.getText(); String stt=jComboBox1.getSelectedItem().toString(); if((st.equals("")&&!(stt.equals("全部")))){ JOptionPane.showMessageDialog(this,"请输入查询条件"); }else{ JOptionPane.showMessageDialog(this ,stt); if(stt.equals("教师编号")){ sql="select * from teacher where teacher_id=?"; ps=database1.createPreparedStatement(sql); ps.setString(1,jTextField1.getText()); }else{ if(stt.equals("教师名字")){ sql="select * from teacher where teacher_name=?"; ps=database1.createPreparedStatement(sql); ps.setString(1,jTextField1.getText()); }else{ if(stt.equals("教师部门编号")){ sql="select * from teacher where department_id=?"; ps=database1.createPreparedStatement(sql); ps.setString(1,jTextField1.getText()); }else{ if(stt.equals("教师性别")){ sql="select * from teacher where teacher_sex=?"; ps=database1.createPreparedStatement(sql); ps.setString(1,jTextField1.getText()); }else{ if(stt.equals("教师类型")){ sql="select * from teacher where teacher_tyee=?"; ps=database1.createPreparedStatement(sql); ps.setString(1,jTextField1.getText()); }else{ if(stt.equals("教师状态")){ sql="select * from teacher where teacher_status=?"; ps=database1.createPreparedStatement(sql); ps.setString(1,jTextField1.getText()); }else{ if(stt.equals("教师学历")){ sql="select * from teacher where educate_level=?"; ps=database1.createPreparedStatement(sql); ps.setString(1,jTextField1.getText()); }else{ if(stt.equals("全部")){ sql="select * from teacher "; ps=database1.createPreparedStatement(sql); } } } } } } }// } rs=ps.executeQuery(); int i=0; while(rs.next()){ if (i < rowdata1.length) { rowdata1[i][0] = rs.getString("teacher_id"); rowdata1[i][1] = rs.getString("department_id"); rowdata1[i][2] = rs.getString("teacher_tyee"); rowdata1[i][3] = rs.getString("teacher_name"); rowdata1[i][4] = rs.getString("teacher_sex"); rowdata1[i][5] = rs.getString("teacher_telephone"); rowdata1[i][6] = rs.getString("teacher_status"); rowdata1[i][7] = rs.getString("teacher_birth"); // rowdata1[i][8] = rs.getString("educate_levele"); i++; } }if(i==0){ JOptionPane.showMessageDialog(this,"没有你要的信息!"); } jTable1.repaint(); ps.close(); } }}class Frame2_jButton2_actionAdapter implements java.awt.event.ActionListener { Frame2 adaptee; Frame2_jButton2_actionAdapter(Frame2 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton2_actionPerformed(e); }}class Frame2_jButton1_actionAdapter implements java.awt.event.ActionListener { Frame2 adaptee; Frame2_jButton1_actionAdapter(Frame2 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { try { adaptee.jButton1_actionPerformed(e); } catch (SQLException ex) { ex.printStackTrace(); } // adaptee.jButton1_actionPerformed(e); // adaptee.jButton1_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -