searchpanel.java~15~

来自「银行信用评估系统」· JAVA~15~ 代码 · 共 242 行

JAVA~15~
242
字号
package management;import java.awt.*;import javax.swing.*;import com.borland.dbswing.*;import java.awt.event.*;import java.sql.*;import com.borland.dx.dataset.*;import com.borland.jbcl.layout.*;import com.borland.dx.sql.dataset.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class searchPanel extends JPanel {  JLabel jLabel2 = new JLabel();  JLabel jLabel3 = new JLabel();  JLabel jLabel4 = new JLabel();  JTextField jTextField1 = new JTextField();  JButton jButton1 = new JButton();  JButton jButton2 = new JButton();  JComboBox jComboBox1 = new JComboBox();  JComboBox jComboBox2 = new JComboBox();  TableScrollPane tableScrollPane1 = new TableScrollPane();  JdbTable jdbTable1 = new JdbTable();  GridBagLayout gridBagLayout1 = new GridBagLayout();  JLabel jLabel5 = new JLabel();  PreparedStatement pstmt;  Connection con;  String query;  ResultSet rs;  String str;  String str1;  String str2;  String str3;  Database database1 = new Database();  QueryDataSet queryDataSet1 = new QueryDataSet();  QueryResolver queryResolver1 = new QueryResolver();  String a[]={"STUDENTNO","STUDENTNAME","STUDENTAGE","STUDENTSEX","STUENTRACE","STUDENTSPECIATION","COURSENAME"  ,"COURSETYPE","COURSETEACHER","COURSETIME","COURSEADDRESS","COURSEWEEK","SCORE","SCORECREDIT","SCORESORT",  "SCORETPYE","SCOREREMARK","SCORETIME"};  String b[]={"学号","姓名","年龄","性别","民族","专业","课程名称","课程类型","任课老师","上课时间","上课地点","上课周次",  "成绩","学分","类别","考别","备注","时间"};  String c[]={"student","course","score"};  String d[]={"学生个人信息表","学生课程表","学生成绩表"};  public searchPanel() {    try {      jbInit();    }    catch(Exception ex) {      ex.printStackTrace();    }  }  void jbInit() throws Exception {    this.setBackground(new Color(131, 223, 227));    this.setForeground(new Color(83, 62, 159));    this.setLayout(gridBagLayout1);    jLabel2.setFont(new java.awt.Font("Dialog", 1, 19));    jLabel2.setForeground(Color.blue);    jLabel2.setText("选择查询的表:");    jLabel3.setFont(new java.awt.Font("Dialog", 1, 19));    jLabel3.setForeground(Color.blue);    jLabel3.setText("选择查询的项:");    jLabel4.setFont(new java.awt.Font("Dialog", 1, 19));    jLabel4.setForeground(Color.blue);    jLabel4.setText("选择查询的内容:");    jTextField1.setText("");    jButton1.setText("确定");    jButton1.addActionListener(new searchPanel_jButton1_actionAdapter(this));    jButton2.setText("重置");    jComboBox1.setSelectedItem(null);    jComboBox1.addItemListener(new searchPanel_jComboBox1_itemAdapter(this));    jLabel5.setFont(new java.awt.Font("Dialog", 1, 40));    jLabel5.setForeground(Color.magenta);    jLabel5.setText("  学 生 查 询 管 理");    database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student", "sa", "lomf8244", false, "com.borland.datastore.jdbc.DataStoreDriver"));    database1.setTransactionIsolation(java.sql.Connection.TRANSACTION_READ_COMMITTED);    queryDataSet1.setResolver(queryResolver1);    queryResolver1.setDatabase(database1);    queryResolver1.setUpdateMode(com.borland.dx.dataset.UpdateMode.KEY_COLUMNS);    jdbTable1.setDataSet(queryDataSet1);    this.add(jLabel3,    new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 15, 0, 9), 9, -1));    this.add(jLabel2,    new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(6, 16, 0, 11), 6, -2));    this.add(jLabel4,    new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 12, 0, 0), 1, -9));    this.add(jTextField1,    new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(8, 0, 0, 0), 107, 0));    this.add(jButton1,    new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(7, 13, 0, 0), -1, 0));    this.add(jButton2,    new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(7, 17, 0, 14), -1, 0));    this.add(jComboBox1,    new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(7, 0, 0, 0), 157, 0));    this.add(jComboBox2,    new GridBagConstraints(1, 2, 2, 1, 1.0, 0.0            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(9, 0, 0, 0), 157, 0));    this.add(tableScrollPane1,    new GridBagConstraints(0, 4, 4, 1, 1.0, 1.0            ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(24, 1, 6, 0), -27, -293));    this.add(jLabel5,              new GridBagConstraints(0, 0, 4, 1, 0.0, 0.0            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 38, 19, 0), 161, -10));    tableScrollPane1.getViewport().add(jdbTable1, null);    jComboBox1.addItem("学生个人信息表");    jComboBox1.addItem("学生课程表");    jComboBox1.addItem("学生成绩表");    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");    String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student";    String username= "sa";    String password= "lomf8244";    con = DriverManager.getConnection(url,username,password);    //query="select * from ? where ?=?";    query="select * from student where STUDENTNO=?";    pstmt = con.prepareStatement(query);  }  void jComboBox1_itemStateChanged(ItemEvent e) {    if(jComboBox1.getSelectedIndex()==0)    {   jComboBox2.removeAllItems();        jComboBox2.addItem("学号");        jComboBox2.addItem("姓名");        jComboBox2.addItem("年龄");        jComboBox2.addItem("性别");        jComboBox2.addItem("民族");        jComboBox2.addItem("专业");    }    else if(jComboBox1.getSelectedIndex()==1)   {   jComboBox2.removeAllItems();       jComboBox2.addItem("学号");       jComboBox2.addItem("课程名称");       jComboBox2.addItem("课程类型");       jComboBox2.addItem("任课老师");       jComboBox2.addItem("上课时间");       jComboBox2.addItem("上课地点");       jComboBox2.addItem("上课周次");    }    else if(jComboBox1.getSelectedIndex()==2)   {   jComboBox2.removeAllItems();       jComboBox2.addItem("学号");       jComboBox2.addItem("课程名称");       jComboBox2.addItem("成绩");       jComboBox2.addItem("学分");       jComboBox2.addItem("类别");       jComboBox2.addItem("考别");       jComboBox2.addItem("备注");       jComboBox2.addItem("时间");    }  }  void jButton1_actionPerformed(ActionEvent e) {   try{        /*  str1=(String)jComboBox1.getSelectedItem();         for(int i=0;i<d.length;i++)           if(str1.equals(d[i]))             str1=c[i];          pstmt.setString(1,str1);          str2=(String)jComboBox2.getSelectedItem();            for(int i=0;i<b.length;i++)             if(str2.equals(b[i]))               str2=a[i];          pstmt.setString(2,str2);          str3=jTextField1.getText();          pstmt.setString(3,str3);         */          str3=jTextField1.getText();          pstmt.setString(1,str3);          rs=pstmt.executeQuery();        /* if(rs.next()){            // queryDataSet1.close();             str=rs.getString(str2);             queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select * from str1 where str2="+str, null, true, Load.ALL));            // queryDataSet1.refresh();             jdbTable1.setDataSet(queryDataSet1);             //jdbTable1.repaint();          }*/        if(rs.next()){            // queryDataSet1.close();             str=rs.getString("STUDENTNO");             queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select * from student where STUDENTNO="+str, null, true, Load.ALL));             queryDataSet1.refresh();             jdbTable1.setDataSet(queryDataSet1);             jdbTable1.repaint();          }         else{         jTextField1.setText("没有结果");         queryDataSet1.close();         queryDataSet1.refresh();         jdbTable1.setDataSet(null);          jdbTable1.repaint();         }    }  catch(SQLException ex) {   System.out.print("系统错误,请重新运行。");     }}}class searchPanel_jComboBox1_itemAdapter implements java.awt.event.ItemListener {  searchPanel adaptee;  searchPanel_jComboBox1_itemAdapter(searchPanel adaptee) {    this.adaptee = adaptee;  }  public void itemStateChanged(ItemEvent e) {    adaptee.jComboBox1_itemStateChanged(e);  }}class searchPanel_jButton1_actionAdapter implements java.awt.event.ActionListener {  searchPanel adaptee;  searchPanel_jButton1_actionAdapter(searchPanel adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jButton1_actionPerformed(e);  }}

⌨️ 快捷键说明

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