⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 teachersearch.java

📁 学生成绩管理系统
💻 JAVA
字号:
/*
 * Teachersearch.java
 *
 * Created on 2007年11月24日, 下午4:12
 */

package javaapplication1;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;

/**
 *
 * @author  mis05
 */
public class Teachersearch extends javax.swing.JPanel {
    
    /** Creates new form Teachersearch */
    public Teachersearch() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        jLabel1.setFont(new java.awt.Font("宋体", 1, 24));
        jLabel1.setText("\u8bfe\u7a0b\u7f16\u53f7");

        jButton1.setText("\u67e5\u8be2\u6b64\u8bfe\u7a0b\u6240\u6709\u6210\u7ee9");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                search(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(49, 49, 49)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1)
                    .add(layout.createSequentialGroup()
                        .add(jLabel1)
                        .add(22, 22, 22)
                        .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(34, 34, 34)
                        .add(jButton1)))
                .addContainerGap(40, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(51, 51, 51)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 146, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 31, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jLabel1)
                    .add(jButton1)
                    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(43, 43, 43))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void search(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_search
 Statement sql;
        
        try{
            Conect conect = new Conect();
            sql = conect.dbConn.createStatement();
            StringBuffer output = new StringBuffer();
            String number = jTextField1.getText();
            String output1;
            String string1;
            string1="select 课程编号 from 课程 where 课程编号='"+number+"'";
            ResultSet resultSet=sql.executeQuery(string1);
           
        ResultSetMetaData metaData=resultSet.getMetaData();
        int numberOfColumns=metaData.getColumnCount();
    
        while(resultSet.next()){
        for(int i=1;i<=numberOfColumns;i++)
           string1=resultSet.getObject(i).toString();
       }
        
            int temp = 0;
            ResultSet rs1 = sql.executeQuery("select 姓名,课程名称,成绩 from 学生,成绩,课程 where 学生.学生编号=成绩.学生编号 and 成绩.课程编号=课程.课程编号 and 成绩.课程编号='"+number+"'");
            ResultSetMetaData metaData1=rs1.getMetaData();
            int numberOfColumns1=metaData1.getColumnCount();
            for(int i=1;i<=numberOfColumns1;i++)
                output.append(metaData1.getColumnName(i)+"\t");
            output.append("\n");
            while( rs1.next() ) {
                 for(int i=1;i<=numberOfColumns1;i++)
               
                output.append(rs1.getObject(i).toString()+"\t");
            output.append("\n");
            }
                                          
            output1 = output.toString();
            jTextArea1.setText( output1 );           
            
        }
        catch(SQLException sqlException){
            JOptionPane.showMessageDialog(null,sqlException.getMessage(),"Database Error",JOptionPane.ERROR_MESSAGE);
            System.exit(1);} catch(ClassNotFoundException classNotFound){
                JOptionPane.showMessageDialog(null,classNotFound.getMessage(),"Driver Not Found",JOptionPane.ERROR_MESSAGE);
                System.exit(1);
            }// TODO add your handling code here:
    }//GEN-LAST:event_search
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
    
}

⌨️ 快捷键说明

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