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

📄 user.java

📁 一个学校当中的教务管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * user.java
 *
 * Created on 2007年7月28日, 下午12:39
 */

package kehu;
import java.sql.*;
import java.util.Vector;
import javax.swing.ListSelectionModel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.*;
import java.awt.Color;
/**
 *
 * @author  徐翘
 */
public class user extends javax.swing.JFrame {
    String userid;
    String ID;
    static boolean isQuery=true; 
    boolean isquery=false;
    String[] aRow;
    String[] Rows;
    //String[][] hehe;
    Connection con;

     
    /** Creates new form user */
    public user() {
        initComponents();
    }
    public user(String INFO,String id)
    {
         initComponents();
         this.setLocationRelativeTo(null);
         ID=id;
         System.out.println("ID"+ID);
 
    }
    
    public void dboperater(String QS)
    {   
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String url="jdbc:odbc:教务";
            Connection con=DriverManager.getConnection(url,"","");            
           Statement stmt=con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
          // Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

            if(isQuery){
            ResultSet rs=stmt.executeQuery(QS);
            ResultSetMetaData rsmd=rs.getMetaData();
            int cols= rsmd.getColumnCount();//得到列数
            aRow=new String[cols];//表头数组
            Rows=new String[cols];//表的内容数组
            boolean more=rs.next();          
            int r=0;//行数   
            int i=0;//列数
            for(i=0;i<cols;i++)
                   aRow[i]=rsmd.getColumnName(i+1);  //得到表头
             
            do{                               
                more=rs.next();      
                r++;
            }while(more);//得到行数
            System.out.println(r);
            DefaultTableModel mm= new DefaultTableModel(aRow,0);            
            rs.beforeFirst();
                 while(rs.next()){                
                 for(i=1;i<=cols;i++){
                     Rows[i-1]=rs.getString(i);                    
                 }                
                 mm.addRow(Rows);                  
                 }                         
              jTable1.setModel(mm);    
              //*********************************************
              if(isquery==true){
                  
               /* jTable1.setRowSelectionAllowed(true);
                  jTable1.setRowSelectionInterval(3,3);
                  jTable1.setSelectionBackground(Color.ORANGE);*/
              
              }
              //**********************************************
              record_jL.setText("有关记录为"+r+"条");}
            else{
               System.out.println("isQuery=false");
                stmt.executeUpdate(QS);
                record_jL.setText("有关记录为"+stmt.getUpdateCount()+"条");
                
            }
            //System.out.println("共有记录:"+r+"条");                       
          } catch (SQLException ex) {
              System.out.println(ex.getErrorCode());
            ex.printStackTrace();
          }  catch (ClassNotFoundException ex) {
            ex.printStackTrace();
          }
    }      
    
     /** 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=" 生成的代码 ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        record_jL = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jMenuItem10 = new javax.swing.JMenuItem();
        jMenuItem11 = new javax.swing.JMenuItem();
        jMenu5 = new javax.swing.JMenu();
        jMenuItem12 = new javax.swing.JMenuItem();
        jMenuItem13 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        DefaultTableModel mm= new DefaultTableModel(); //定义一个表的模板
        jTable1.setModel(/*new DefaultTableModel(mm)*/mm
        );
        System.out.println("初始化后");
        jScrollPane1.setViewportView(jTable1);

        jLabel1.setText("\u67e5\u627e");

        jTextField1.setToolTipText("\u8bf7\u8f93\u5165\u8981\u67e5\u627e\u5b66\u751f\u7684\u59d3\u540d\u6216\u8005\u5b66\u53f7");

        jButton1.setText("\u786e\u5b9a");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jLabel1)
                        .add(22, 22, 22)
                        .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 139, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 81, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(record_jL, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 112, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 252, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 8, Short.MAX_VALUE)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(record_jL, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel1)
                    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jButton1))
                .addContainerGap())
        );
        getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);

        jMenu1.setText("\u4e2a\u4eba\u4fe1\u606f");
        jMenuItem1.setText("\u57fa\u672c\u8d44\u6599\n");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });

        jMenu1.add(jMenuItem1);

        jMenuItem2.setText("\u8bfe\u7a0b\u8868");

⌨️ 快捷键说明

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