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

📄 asstoprofesion1.java

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

package javaapplication1;

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

/**
 *
 * @author  mis05
 */
public class Asstoprofesion1 extends javax.swing.JFrame {
    
    /** Creates new form Asstoprofesion1 */
    public Asstoprofesion1() {
        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();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel1.setText("\u4e13\u4e1a\u7f16\u53f7");

        jLabel2.setText("\u4e13\u4e1a\u540d\u79f0");

        jLabel3.setText("\u6240\u5c5e\u5b66\u9662\u7f16\u53f7");

        jLabel4.setText("\u5b66\u4f4d\u79cd\u7c7b");

        jButton1.setText("\u6dfb\u52a0");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                add(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(100, 100, 100)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(jLabel2)
                    .add(jLabel3)
                    .add(jLabel4))
                .add(7, 7, 7)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jTextField4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                    .add(jTextField3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                    .add(jTextField2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 106, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(115, 115, 115))
            .add(layout.createSequentialGroup()
                .add(159, 159, 159)
                .add(jButton1)
                .addContainerGap(184, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(40, 40, 40)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(30, 30, 30)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(27, 27, 27)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(29, 29, 29)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(jTextField4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(24, 24, 24)
                .add(jButton1)
                .addContainerGap(47, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void add(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_add
Statement sql;
        
        try{
            Conect conect = new Conect();
            sql = conect.dbConn.createStatement();
            
            String number = jTextField1.getText();
            String name = jTextField2.getText();
            String collegeNo = jTextField3.getText();
            String kind = jTextField4.getText();
            int temp = 1;
            
            if( number.equals("") )
            {
                JOptionPane.showMessageDialog(null,"专业编号不能为空","错误",JOptionPane.ERROR_MESSAGE);
            }
            else
            {
                ResultSet rs1 = sql.executeQuery("SELECT 专业编号 from 专业 where 专业编号 ='"+number+"'");
                if( rs1.next() )
                {
                    JOptionPane.showMessageDialog(null,"已存在此专业编号","错误",JOptionPane.ERROR_MESSAGE);
                    temp --;
                }  
                
                rs1 = sql.executeQuery("SELECT 学院编号 FROM 学院 WHERE 学院编号 ='"+ collegeNo +"'");
                if( rs1.next() )
                {
                    collegeNo = rs1.getObject(1).toString();
                    temp ++;
                }
                else JOptionPane.showMessageDialog(null,"不存在该学院","错误",JOptionPane.ERROR_MESSAGE);
                
                if( temp == 2 )
                {   
                    String update = "INSERT into 专业 (专业编号,专业名称,所属学院编号,学位种类) values ('"+number+"','"+name+"','"+collegeNo+"','"+kind+"')";
                    
                    int reg;                
                    reg = sql.executeUpdate( update );
                    
                    JOptionPane.showMessageDialog(null,"已成功新建专业","成功",JOptionPane.INFORMATION_MESSAGE);
                    dispose();
                }
            }
            
        } 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_add
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Asstoprofesion1().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    // End of variables declaration//GEN-END:variables
    
}

⌨️ 快捷键说明

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