Java+Eclipse+MySQL+Swing realizes the student examination result management system (free complete project)

Copyright statement: originality is not easy, plagiarism and reprinting are prohibited in this article, and infringement must be investigated!

1. Requirements development document

Complete list of project files:
insert image description here
Screenshots of requirements development documents:
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

2. Database design document

Partial screenshot of the database design document:
insert image description here
insert image description here
insert image description here
insert image description here

3. Part of the code and effect display of the function module

Database class:

package system_of_database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtil {
    
    

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    public Connection getConnection() throws ClassNotFoundException,
            SQLException,InstantiationException,IllegalAccessException {
    
    
        String driver = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/exam_of_students?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";
        String user = "root";
        String password = "root";
        try {
    
    
            Class.forName(driver);
            con = DriverManager.getConnection(url,user,password);
            return con;
        } catch(Exception e) {
    
    
            throw new SQLException("驱动错误或连接失败!");
        }
    }

Candidate login code is as follows:
public class LoginListener implements ActionListener{
    
    
        public void actionPerformed(ActionEvent e) {
    
    
            lblMsg1.setText("");
            lblMsg2.setText("");
            user = userService.findUserByName(txtName.getText().trim());
            if(user != null) {
    
    
                if(user.getPassword().equals(new String(txtPwd.getPassword()))) {
    
    
                    LoginFrame_Of_Students.this.setVisible(false);
                    new MainFrame_Of_Students();
                } else {
    
    
                    lblMsg2.setText("密码错误!");
                    txtPwd.setText("");
                }
            } else {
    
    
                lblMsg1.setText("该考生不存在 !");
            }
        }
    }

Candidate login results are as follows:
insert image description here

The administrator login part of the code is as follows:

public class LoginListener implements ActionListener{
    
    
        public void actionPerformed(ActionEvent e) {
    
    
            lblMsg1.setText("");
            lblMsg2.setText("");
            user = userService.findUserByName(txtName.getText().trim());
            if(user != null) {
    
    
                if(user.getPassword().equals(new String(txtPwd.getPassword()))) {
    
    
                    LoginFrame_Of_Administration.this.setVisible(false);
                    new MainFrame_Of_Administration();
                } else {
    
    
                    lblMsg2.setText("密码错误!");
                    txtPwd.setText("");
                }
            } else {
    
    
                lblMsg1.setText("该管理员不存在 !");
            }
        }
    }

    public class ResetListener implements ActionListener{
    
    
        public void actionPerformed(ActionEvent e) {
    
    
            txtName.setText("");
            txtPwd.setText("");
        }
    }

The effect of the administrator login is as follows:
insert image description here
the codes of the examinee’s query results are as follows:

private void showData() {
    
    
        String id = txtId.getText();
        String sql = "select id as 考生号,geography as 地理,chemistry as 化学,IT as 信息技术,History as 历史 ,Biology as 生物,mathematics as 数学,general_technique as 通用技术,physics as 物理,english as 英语,chinese as 语文,politics as 政治  from information_of_grade where id = '"+id+"'";
        DBUtil db = new DBUtil();
        try {
    
    
            db.getConnection();
            ResultSet rs = db.executeQuery(sql, null);
            ResultSetMetaData rsmd = rs.getMetaData();
            int colCount = rsmd.getColumnCount();
            Vector<String> title = new Vector<String>();  //存放标题
            for(int i = 1;i<=colCount;i++) {
    
    
                title.add(rsmd.getColumnLabel(i));
            }
            Vector<Vector<String>> data = new Vector<Vector<String>>();    //存放表格数据
            int rowCount = 0;
            while(rs.next()) {
    
    
                rowCount++;
                Vector<String> rowdata = new Vector<String>();         //存放行数据
                for(int i = 1;i<=colCount;i++) {
    
    
                    rowdata.add(rs.getString(i));
                }
                data.add(rowdata);
            }
            if(rowCount == 0) {
    
    
                model.setDataVector(null, title);
            } else {
    
    
                model.setDataVector(data,title);
            }
        } catch(Exception ee) {
    
    
            System.out.println(ee.toString());
            JOptionPane.showMessageDialog(this, "系统出现异常错误。请检查数据库。系统即将推出!!!","错误",0);
        } finally {
    
    
            db.closeAll();
        }
        JOptionPane.showMessageDialog(null, "查询到该考生信息");
    }

Candidates query results are as follows:
insert image description here
Candidates’ results export part code is as follows:

public void saveFile() {
    
    
        JFileChooser fc = new JFileChooser();
        int rVal = fc.showSaveDialog(this);
        if(rVal == JFileChooser.APPROVE_OPTION) {
    
    
            String fileName = fc.getSelectedFile().getName();
            String path = fc.getCurrentDirectory().toString();
            try {
    
    
                TableModel model = table.getModel(); 
                FileWriter fw = new FileWriter(path + "/" + fileName);
                for(int i=0; i < model.getColumnCount(); i++) {
    
     
                    fw.write(model.getColumnName(i) + "\t"); 
                } 
                fw.write("\n"); 
                for(int i=0; i< model.getRowCount(); i++) {
    
     
                    for(int j=0; j < model.getColumnCount(); j++) {
    
     
                        fw.write(model.getValueAt(i,j).toString()+"\t"); 
                    } 
                    fw.write("\n");
                } 
                fw.close();
            } catch(Exception e) {
    
    
                e.printStackTrace();
            }
            JOptionPane.showMessageDialog(null, "导出成功");
        }
    }

The results of the test taker’s export result are as follows:
insert image description here
the part of the code for the test taker to modify the password is as follows:

public class listener_of_delete implements ActionListener{
    
    
           public void actionPerformed(ActionEvent e){
    
    
               String id = jtId.getText();
               String code = new String(jpCode.getPassword());
               String code1 = new String(jpCode1.getPassword());
               DBUtil db = new DBUtil();
               String sql = "update information_of_students set pwd = '"+code+"' where id = '"+id+"'";
               if(code.equals(code1)){
    
    
                   try {
    
    
                       db.getConnection();
                       db.executeUpdate(sql,null);
                   } catch(Exception ee) {
    
    
                       System.out.println(ee.toString());
                   } finally {
    
    
                       db.closeAll();
                   }
                   JOptionPane.showMessageDialog(null, "修改成功");
               }
               else{
    
    
                   JOptionPane.showMessageDialog(null, "两次密码不一样!");
               }
           }
    }

Candidates modify the password as follows:
insert image description here
part of the code of the administrator’s main panel is as follows:

public MainFrame_Of_Administration() {
    
    
        super("Administration");
        ImageIcon qstIcon = new ImageIcon("images\\1.png");
        this.setIconImage(qstIcon.getImage());
        p = new JPanel();
        setBak();
        clipboard=getToolkit().getSystemClipboard();
        Container c = getContentPane();
        p.setOpaque(false);
        c.add(p);
        p.setLayout(null);

        jbInsert = new JButton("添加考生信息");
        jbDelete = new JButton("删除考生信息");
        jbUpdate = new JButton("修改考生信息");
        jbAdministration = new JButton("返回登录界面");
        jbResetCode = new JButton("重置考生密码");

        jbAdministration.addActionListener(new loginframe_of_administration());
        jbDelete.addActionListener(new listener_of_delete());
        jbInsert.addActionListener(new listener_of_insert());
        jbUpdate.addActionListener(new listener_of_update());
        jbResetCode.addActionListener(new listener_of_reset());

        jbInsert.setBounds(0,20,120,25);
        jbDelete.setBounds(0,55,120,25);
        jbUpdate.setBounds(0,90,120,25);
        jbAdministration.setBounds(0,125,120,25);
        jbResetCode.setBounds(0,165,120,25);

        p.add(jbInsert);
        p.add(jbDelete);
        p.add(jbUpdate);
        p.add(jbAdministration);
        p.add(jbResetCode);
        this.add(p);
        this.setLocation(200,100);
        this.setSize(533,300);
        this.setResizable(false);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

The effect of the administrator's main panel is as follows:
insert image description here
the code for adding candidate information is as follows:

public class listener_of_insert implements ActionListener{
    
    
           public void actionPerformed(ActionEvent e){
    
    
               DBUtil db = new DBUtil();
               String preparedsql = "insert into information_of_grade(id,geography,chemistry,IT,history,biology,mathematics,general_technique,physics,english,chinese,politics)"+"values(?,?,?,?,?,?,?,?,?,?,?,?)";

               try {
    
    
                   db.getConnection();
                   Object param[] = {
    
    jtId.getText(),jtGeo.getText(),jtChe.getText(),jtIT.getText(),jtHis.getText(),jtBio.getText(),jtMath.getText(),jtGen.getText(),jtPhy.getText(),jtEng.getText(),jtChi.getText(),jtPol.getText()};
                   db.executeUpdate(preparedsql, param);
               } catch(Exception ee) {
    
    
                   System.out.println(ee.toString());
               } finally {
    
    
                   db.closeAll();
               }
               JOptionPane.showMessageDialog(null, "成功添加考生信息");
        }
    }

The effect of adding candidate information is as follows:
insert image description here
the code for deleting candidate information is as follows:

public class listener_of_delete implements ActionListener{
    
    
           public void actionPerformed(ActionEvent e){
    
    
               String id = jtId.getText();
               DBUtil db = new DBUtil();
               String sql = "delete from information_of_grade where id = '"+id+"'";

               try {
    
    
                   db.getConnection();
                   db.executeUpdate(sql,null);
               } catch(Exception ee) {
    
    
                   System.out.println(ee.toString());
               } finally {
    
    
                   db.closeAll();
               }
               JOptionPane.showMessageDialog(null, "成功删除考生信息");
        }
    }

The effect of deleting candidate information is as follows:
insert image description here
Modify the candidate information part of the code as follows:

public class listener_of_delete implements ActionListener{
    
    
           public void actionPerformed(ActionEvent e){
    
    
               String id = jtId.getText();
               String code = new String(jpCode.getPassword());
               String code1 = new String(jpCode1.getPassword());
               DBUtil db = new DBUtil();
               String sql = "update information_of_students set pwd = '"+code+"' where id = '"+id+"'";
               if(code.equals(code1)){
    
    
                   try {
    
    
                       db.getConnection();
                       db.executeUpdate(sql,null);
                   } catch(Exception ee) {
    
    
                       System.out.println(ee.toString());
                   } finally {
    
    
                       db.closeAll();
                   }
                   JOptionPane.showMessageDialog(null, "修改成功");
               }
               else{
    
    
                   JOptionPane.showMessageDialog(null, "两次密码不一样!");
               }
           }
    }

The effect of modifying candidate information is as follows:
insert image description here
Part of the code for resetting the candidate password is as follows:

public class listener_of_delete implements ActionListener{
    
    
           public void actionPerformed(ActionEvent e){
    
    
               String id = jtId.getText();
               DBUtil db = new DBUtil();
               String sql = "update information_of_students set pwd = '000000' where id = '"+id+"'";
               try {
    
    
                   db.getConnection();
                   db.executeUpdate(sql,null);
               } catch(Exception ee) {
    
    
                   System.out.println(ee.toString());
               } finally {
    
    
                   db.closeAll();
                 }
                 JOptionPane.showMessageDialog(null, "重置成功");
           }
    }

The effect of resetting the candidate password is as follows:
insert image description here

4. Download the complete source code

Download the source code of the student examination result management system:

  • Follow my original WeChat public account: " Xiaohong Xingkong Technology ", reply " Students' Examination Results Management System " to get the complete project
    insert image description here

5. Author Info

Author: Xiaohong's Fishing Daily, Goal: Make programming more interesting!

Original WeChat public account: " Xiaohong Xingkong Technology ", focusing on algorithms, web crawlers, website development, game development, data analysis, natural language processing, AI, etc., looking forward to your attention, let us grow and code together!

Copyright Note: This article prohibits plagiarism and reprinting, and infringement must be investigated!

Guess you like

Origin blog.csdn.net/qq_44000141/article/details/122275351