📄 searchpanel2.java~87~
字号:
package management;import java.awt.*;import javax.swing.*;import com.borland.dx.sql.dataset.*;import com.borland.dbswing.*;import java.sql.*;import com.borland.dx.dataset.*;import com.borland.jbcl.layout.*;import com.borland.dx.sql.dataset.*;import java.awt.event.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class searchPanel2 extends JPanel { JLabel jLabel1 = new JLabel(); JTextField jTextField1 = new JTextField(); JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JComboBox jComboBox1 = new JComboBox(); JComboBox jComboBox2 = new JComboBox(); Database database1 = new Database(); TableScrollPane tableScrollPane1 = new TableScrollPane(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); JdbTable jdbTable1 = new JdbTable(); PreparedStatement pstmt; Connection con; String query; ResultSet rs; String str; String str1; String str2; String str3; String str4; 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[]={"学生个人信息表","学生课程表","学生成绩表"}; JTextField jTextField2 = new JTextField(); GridBagLayout gridBagLayout1 = new GridBagLayout(); JLabel jLabel5 = new JLabel(); QueryDataSet queryDataSet1 = new QueryDataSet(); QueryResolver queryResolver1 = new QueryResolver(); String ip; public searchPanel2() { try { jbInit(); } catch(Exception ex) { ex.printStackTrace(); } } void jbInit() throws Exception { jLabel1.setFont(new java.awt.Font("Dialog", 1, 19)); jLabel1.setText("选择查询的表:"); this.setLayout(gridBagLayout1); jTextField1.setText(""); jLabel2.setFont(new java.awt.Font("Dialog", 1, 19)); jLabel2.setText("选择查询的项:"); jLabel3.setFont(new java.awt.Font("Dialog", 1, 19)); jLabel3.setText("输入查询的内容:"); jComboBox1.addItemListener(new searchPanel2_jComboBox1_itemAdapter(this)); jComboBox2.addItemListener(new searchPanel2_jComboBox2_itemAdapter(this)); tableScrollPane1.getViewport().setBackground(SystemColor.info); tableScrollPane1.setForeground(UIManager.getColor("List.background")); jButton1.setText("确定"); jButton1.addActionListener(new searchPanel2_jButton1_actionAdapter(this)); jButton2.setVerifyInputWhenFocusTarget(true); jButton2.setText("清除"); jButton2.addActionListener(new searchPanel2_jButton2_actionAdapter(this)); database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student", "sa", "lomf8244", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver")); database1.setTransactionIsolation(java.sql.Connection.TRANSACTION_READ_COMMITTED); database1.setUseTransactions(false); jdbTable1.setBackground(Color.cyan); jdbTable1.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); jdbTable1.setSelectionBackground(UIManager.getColor("MenuItem.selectionForeground")); jdbTable1.setSelectionForeground(Color.red); jdbTable1.setDataSet(queryDataSet1); jdbTable1.setEditableFocusedCellForeground(SystemColor.activeCaption); jTextField2.setBounds(new Rectangle(197, 12, 77, 22)); this.setBackground(UIManager.getColor("ToolTip.background")); this.setForeground(SystemColor.activeCaption); this.setDebugGraphicsOptions(0); jLabel5.setFont(new java.awt.Font("Dialog", 1, 40)); jLabel5.setForeground(Color.magenta); jLabel5.setText(" 学 生 查 询 管 理"); queryDataSet1.setResolver(queryResolver1); queryResolver1.setDatabase(database1); queryResolver1.setUpdateMode(com.borland.dx.dataset.UpdateMode.KEY_COLUMNS); this.add(jTextField1, new GridBagConstraints(1, 3, 2, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(18, 6, 0, 30), 228, 0)); this.add(jLabel3, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(18, 11, 0, 9), 8, -5)); this.add(jLabel2, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(18, 9, 0, 30), 9, -11)); this.add(jLabel1, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 11, 0, 34), 3, -1)); this.add(jComboBox2, new GridBagConstraints(1, 2, 2, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(13, 6, 0, 28), 209, 0)); this.add(tableScrollPane1, new GridBagConstraints(0, 5, 3, 1, 1.0, 1.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 0, 0, 0), -15, -209)); tableScrollPane1.getViewport().add(jdbTable1, null); this.add(jButton2, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(20, 62, 0, 0), 16, 0)); this.add(jButton1, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(20, 115, 0, 0), 16, 0)); this.add(jComboBox1, new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 29), 208, 0)); this.add(jLabel5, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 272, 0)); 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); str2="STUDENTNO"; //初始化 } void jButton1_actionPerformed(ActionEvent e) { try{ query="select * from "+str1+" where "+str2+"=?"; pstmt = con.prepareStatement(query); str3=jTextField1.getText(); pstmt.setString(1,str3); rs=pstmt.executeQuery(); if(rs.next()){ queryDataSet1.close(); str=rs.getString(str2); if(str1.equals("student")) { str4= "select STUDENTNO as"+ "\'"+"学号" +"\'"+",STUDENTNAME as"+ "\'"+"姓名" +"\'"+",STUDENTAGE as"+ "\'"+"年龄" +"\'"+",STUDENTSEX as"+ "\'"+"性别" +"\'"+",STUENTRACE as"+ "\'"+"民族" +"\'"+",STUDENTSPECIATION as"+ "\'"+"专业" +"\'"+"from "+str1+" where "+str2+"="+"\'"+str+"\'"; } else if(str1.equals("course")) { str4= "select STUDENTNO as"+ "\'"+"学号" +"\'"+",COURSENAME as"+ "\'"+"课程名称" +"\'"+",COURSETYPE as"+ "\'"+"课程类型" +"\'"+",COURSETEACHER as"+ "\'"+"任课老师" +"\'"+",COURSETIME as"+ "\'"+"上课时间" +"\'"+",COURSEADDRESS as"+ "\'"+"上课地点" +"\'"+",COURSEWEEK as"+ "\'"+"上课周次" +"\'"+"from "+str1+" where "+str2+"="+"\'"+str+"\'"; } else{ str4= "select STUDENTNO as"+ "\'"+"学号" +"\'"+",COURSENAME as"+ "\'"+"课程名称" +"\'"+",SCORE as"+ "\'"+"成绩" +"\'"+",SCORECREDIT as"+ "\'"+"学分" +"\'"+",SCORESORT as"+ "\'"+"类别" +"\'"+",SCORETPYE as"+ "\'"+"考别" +"\'"+",SCOREREMARK as"+ "\'"+"备注" +"\'"+",SCORETIME as"+ "\'"+"时间" +"\'"+"from "+str1+" where "+str2+"="+"\'"+str+"\'"; } queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, str4, null, true, Load.ALL)); queryDataSet1.refresh(); jdbTable1.setDataSet(queryDataSet1); jdbTable1.repaint(); } else{ jTextField1.setText("学号不存在!"); queryDataSet1.close(); queryDataSet1.refresh(); jdbTable1.setDataSet(null); jdbTable1.repaint(); } } catch(Exception ef) { System.out.print("系统错误,请重新运行。"); } } 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("时间"); } str1=(String)jComboBox1.getSelectedItem(); for(int i=0;i<d.length;i++) if(str1.equals(d[i])) str1=c[i]; } void jComboBox2_itemStateChanged(ItemEvent e) { for(int i=0;i<8;i++) if(jComboBox2.getSelectedIndex()==i) str2=(String)jComboBox2.getSelectedItem(); for(int i=0;i<b.length;i++) if(str2.equals(b[i])) str2=a[i]; } void jButton2_actionPerformed(ActionEvent e) { jTextField1.setText(""); queryDataSet1.close(); queryDataSet1.refresh(); jdbTable1.setDataSet(null); jdbTable1.repaint(); }}class searchPanel2_jButton1_actionAdapter implements java.awt.event.ActionListener { searchPanel2 adaptee; searchPanel2_jButton1_actionAdapter(searchPanel2 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); }}class searchPanel2_jComboBox1_itemAdapter implements java.awt.event.ItemListener { searchPanel2 adaptee; searchPanel2_jComboBox1_itemAdapter(searchPanel2 adaptee) { this.adaptee = adaptee; } public void itemStateChanged(ItemEvent e) { adaptee.jComboBox1_itemStateChanged(e); }}class searchPanel2_jComboBox2_itemAdapter implements java.awt.event.ItemListener { searchPanel2 adaptee; searchPanel2_jComboBox2_itemAdapter(searchPanel2 adaptee) { this.adaptee = adaptee; } public void itemStateChanged(ItemEvent e) { adaptee.jComboBox2_itemStateChanged(e); }}class searchPanel2_jButton2_actionAdapter implements java.awt.event.ActionListener { searchPanel2 adaptee; searchPanel2_jButton2_actionAdapter(searchPanel2 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton2_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -