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

📄 teacherscore.java

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

package javaapplication1;

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

/**
 *
 * @author  mis05
 */
public class Teacherscore extends javax.swing.JPanel {
    
    /** Creates new form Teacherscore */
    public Teacherscore() {
        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();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        jLabel1.setText("\u5b66\u751f\u7f16\u53f7");

        jLabel2.setText("\u8bfe\u7a0b\u7f16\u53f7");

        jLabel3.setText("\u6210\u7ee9");

        jButton1.setText("\u5f55\u5165");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enter(evt);
            }
        });

        jButton2.setText("\u4fee\u6539");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                change(evt);
            }
        });

        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(111, 111, 111)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jButton1)
                        .add(47, 47, 47)
                        .add(jButton2))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .add(37, 37, 37)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jTextField2)
                            .add(jTextField1)
                            .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 83, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(121, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(56, 56, 56)
                .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(37, 37, 37)
                .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(38, 38, 38)
                .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(30, 30, 30)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton1)
                    .add(jButton2))
                .addContainerGap(56, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void change(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_change
Statement sql;
      try{
          Conect conect = new Conect();
          sql = conect.dbConn.createStatement();
          
         String number = jTextField1.getText();
         String course = jTextField2.getText();
         String score = jTextField3.getText();        
         int temp=0;
         
         if( number.equals("")|| course.equals("") )
            {
                JOptionPane.showMessageDialog(null,"学生编号和课程编号不能为空","错误",JOptionPane.ERROR_MESSAGE);
            }
         else
            {
                ResultSet rs1 = sql.executeQuery("SELECT 学生编号 from 学生 where 学生编号 ='"+number+"'");
                if( rs1.next() )
                {
                    temp++;
                }
                else JOptionPane.showMessageDialog(null,"不存在此学生编号","错误",JOptionPane.ERROR_MESSAGE);
                
                ResultSet rs2 = sql.executeQuery("SELECT 课程编号 from 课程 where 课程编号 ='"+course+"'");
                if( rs2.next() )
                {
                    temp++;
                }
                else JOptionPane.showMessageDialog(null,"不存在此课程编号","错误",JOptionPane.ERROR_MESSAGE);
            }
         if(temp == 2){
            String update = "UPDATE  成绩 SET 成绩 = '"+score+"' WHERE 学生编号 = '"+number+"' and 课程编号 = '"+course+"'";
                        int reg;
                        reg = sql.executeUpdate( update );
                        JOptionPane.showMessageDialog (null,"已成功修改成绩","成功",JOptionPane.INFORMATION_MESSAGE);
         }
             
      }
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_change

    private void enter(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enter
         Statement sql;
      try{
          Conect conect = new Conect();
          sql = conect.dbConn.createStatement();
          
         String number = jTextField1.getText();
         String course = jTextField2.getText();
         String score = jTextField3.getText();        
         int temp=0;
         
         if( number.equals("")|| course.equals("") )
            {
                JOptionPane.showMessageDialog(null,"学生编号和课程编号不能为空","错误",JOptionPane.ERROR_MESSAGE);
            }
         else
            {
                ResultSet rs1 = sql.executeQuery("SELECT 学生编号 from 学生 where 学生编号 ='"+number+"'");
                if( rs1.next() )
                {
                    temp++;
                }
                else JOptionPane.showMessageDialog(null,"不存在此学生编号","错误",JOptionPane.ERROR_MESSAGE);
                
                ResultSet rs2 = sql.executeQuery("SELECT 课程编号 from 课程 where 课程编号 ='"+course+"'");
                if( rs2.next() )
                {
                    temp++;
                }
                else JOptionPane.showMessageDialog(null,"不存在此课程编号","错误",JOptionPane.ERROR_MESSAGE);
            }
         if(temp == 2){
            String update = "INSERT into 成绩 (学生编号,课程编号,成绩) values ('"+number+"','"+course+"','"+score+"')";
                        int reg;
                        reg = sql.executeUpdate( update );
                        JOptionPane.showMessageDialog (null,"已成功录入成绩","成功",JOptionPane.INFORMATION_MESSAGE);
         }
             
      }
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_enter
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration//GEN-END:variables

    
}

⌨️ 快捷键说明

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