java学生成绩管理系统

article/2025/9/28 8:16:54

学生成绩管理系统

使用java swing 和 jdbc 技术 管理学生信息

文章目录

  • 学生成绩管理系统
  • 一,总体架构
  • 二、controller层的编写
  • 三、pojo层的编写
  • 四,view层的编写
  • 五,数据库的连接
  • 六,启动程序

一,总体架构

五个包
一共五个包

二、controller层的编写

包含select及update两个核心类的编写,以后的按钮绑定的事件会使用其中的函数。
select类如下

package Controller;import POJO.Student;
import POJO.StudentCourse;
import POJO.inputStudentInfo;
import Utils.DbConnection;import java.io.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;public class Select {// 查询执行行数public int userloginSelect(String sql) {ResultSet resultSet = DbConnection.query(sql);int a = 0;try {while (resultSet.next()) {a = resultSet.getInt(1);}} catch (SQLException e) {e.printStackTrace();}return a;}//查询全部的学生public Object[][] selectStudentAll(){String sql = "SELECT * FROM student ";System.out.println(sql);Connection conn = DbConnection.getConnection();PreparedStatement stmt = null;ResultSet rs = null;ArrayList<Student> list = new ArrayList<Student>();try {stmt = (PreparedStatement) conn.prepareStatement(sql);rs = stmt.executeQuery();while (rs.next()) {Student student = new Student();student.setID(rs.getInt(1));student.setName(rs.getString(2));student.setSex(rs.getString(3));student.setDateOfBirth(rs.getString(4));student.setStudentID(rs.getString(5));list.add(student);}} catch (SQLException e1) {e1.printStackTrace();} finally {try {DbConnection.colse(rs, stmt, conn);} catch (Exception e) {e.printStackTrace();}}Object[][] objects = new Object[list.size()][5];for (int i = 0; i < list.size(); i++) {objects[i][0] = list.get(i).getID();objects[i][1] = list.get(i).getName();objects[i][2] = list.get(i).getSex();objects[i][3] = list.get(i).getDateOfBirth();objects[i][4] = list.get(i).getStudentID();}return objects;}//根据姓名查询学生信息public Object[][] selectStudentByName(String name){String sql = "SELECT * FROM student where  name = '"+name+"'";Connection conn = DbConnection.getConnection();PreparedStatement stmt = null;ResultSet rs = null;ArrayList<Student> list = new ArrayList<Student>();try {stmt = (PreparedStatement) conn.prepareStatement(sql);rs = stmt.executeQuery();while (rs.next()) {Student student = new Student();student.setID(rs.getInt(1));student.setName(rs.getString(2));student.setSex(rs.getString(3));student.setDateOfBirth(rs.getString(4));student.setStudentID(rs.getString(5));list.add(student);}} catch (SQLException e1) {e1.printStackTrace();} finally {try {DbConnection.colse(rs, stmt, conn);} catch (Exception e) {e.printStackTrace();}}Object[][] objects = new Object[list.size()][5];for (int i = 0; i < list.size(); i++) {objects[i][0] = list.get(i).getID();objects[i][1] = list.get(i).getName();objects[i][2] = list.get(i).getSex();objects[i][3] = list.get(i).getDateOfBirth();objects[i][4] = list.get(i).getStudentID();}return objects;}//查询全部的学生对应的成绩public Object[][] selectStudentCourseAll(){String sql = "SELECT * FROM studentcourse ";System.out.println(sql);Connection conn = DbConnection.getConnection();PreparedStatement stmt = null;ResultSet rs = null;ArrayList<StudentCourse> list = new ArrayList<>();try {stmt = (PreparedStatement) conn.prepareStatement(sql);rs = stmt.executeQuery();while (rs.next()) {StudentCourse student = new StudentCourse();student.setId(rs.getInt(1));student.setStudentName(rs.getString(2));student.setCourseName(rs.getString(3));student.setCourseGrade(rs.getInt(4));student.setStudentID(rs.getString(5));list.add(student);}} catch (SQLException e1) {e1.printStackTrace();} finally {try {DbConnection.colse(rs, stmt, conn);} catch (Exception e) {e.printStackTrace();}}Object[][] objects = new Object[list.size()][5];for (int i = 0; i < list.size(); i++) {objects[i][0] = list.get(i).getId();objects[i][1] = list.get(i).getStudentName();objects[i][2] = list.get(i).getCourseName();objects[i][3] = list.get(i).getCourseGrade();objects[i][4] = list.get(i).getStudentID();}return objects;}//根据课程查询成绩信息public Object[][] selectStudentCourseByCourseName(String name){String sql = "SELECT * FROM studentcourse  where  course_name = '"+name+"'";System.out.println(sql);Connection conn = DbConnection.getConnection();PreparedStatement stmt = null;ResultSet rs = null;ArrayList<StudentCourse> list = new ArrayList<>();try {stmt = (PreparedStatement) conn.prepareStatement(sql);rs = stmt.executeQuery();while (rs.next()) {StudentCourse student = new StudentCourse();student.setId(rs.getInt(1));student.setStudentName(rs.getString(2));student.setCourseName(rs.getString(3));student.setCourseGrade(rs.getInt(4));student.setStudentID(rs.getString(5));list.add(student);}} catch (SQLException e1) {e1.printStackTrace();} finally {try {DbConnection.colse(rs, stmt, conn);} catch (Exception e) {e.printStackTrace();}}Object[][] objects = new Object[list.size()][5];for (int i = 0; i < list.size(); i++) {objects[i][0] = list.get(i).getId();objects[i][1] = list.get(i).getStudentName();objects[i][2] = list.get(i).getCourseName();objects[i][3] = list.get(i).getCourseGrade();objects[i][4] = list.get(i).getStudentID();}return objects;}//导出成绩public void inputInfo() throws IOException {FileWriter fileWriter = new FileWriter(new File("info.txt"));String sql = " SELECT course_name,max(course_grade),min(course_grade),avg(course_grade)\n" +"FROM test.studentcourse\n" +"group by course_name;\n" +";";System.out.println(sql);Connection conn = DbConnection.getConnection();PreparedStatement stmt = null;ResultSet rs = null;ArrayList<inputStudentInfo> list = new ArrayList<>();try {stmt = (PreparedStatement) conn.prepareStatement(sql);rs = stmt.executeQuery();while (rs.next()) {inputStudentInfo info = new inputStudentInfo();info.setName(rs.getString(1));info.setMax(rs.getInt(2));info.setMin(rs.getInt(3));info.setAvg(rs.getDouble(4));list.add(info);}} catch (SQLException e1) {e1.printStackTrace();} finally {try {DbConnection.colse(rs, stmt, conn);} catch (Exception e) {e.printStackTrace();}}list.forEach(x->{try {fileWriter.write("课程名称:"+x.getName()+"课程最高分"+x.getMax()+"课程最低分:"+x.getMin()+"课程平均分"+x.getAvg()+"\n");} catch (IOException e) {throw new RuntimeException(e);}});fileWriter.close();}}

update类的编写

package Controller;import Utils.DbConnection;import javax.swing.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;public class Updata {// 添加数据public int addData(String sql) {Connection conn = DbConnection.getConnection();// 获取连接PreparedStatement stmt = null;ResultSet rs = null;try {System.out.println(sql);stmt = conn.prepareStatement(sql);int executeUpdate = stmt.executeUpdate();return executeUpdate;} catch (SQLException e) {JOptionPane.showMessageDialog(null, "执行语句出错\n" + e.toString());e.printStackTrace();}finally {try {DbConnection.colse(rs, stmt, conn);} catch (Exception e) {e.printStackTrace();}}return 0;}}

三、pojo层的编写

对应的数据库表的实体类

管理员类的编写

package POJO;//管理类
public class Admin {//数据库对应ID,方便操作private Integer ID;//用户名private String username;//密码private String password;public Admin(Integer ID, String username, String password, String nickName) {this.ID = ID;this.username = username;this.password = password;}public Integer getID() {return ID;}public void setID(Integer ID) {this.ID = ID;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}}

inputstudentinfo类的编写(接收和处理要导出的成绩信息)

package POJO;/*** @program:school* @author: jiage* @Time: 2022/6/15  20:54**/
public class inputStudentInfo {private String name;private Integer max;private Integer min;private Double avg;public inputStudentInfo(String name, Integer max, Integer min, Double avg) {this.name = name;this.max = max;this.min = min;this.avg = avg;}public inputStudentInfo() {}public String getName() {return name;}public void setName(String name) {this.name = name;}public Integer getMax() {return max;}public void setMax(Integer max) {this.max = max;}public Integer getMin() {return min;}public void setMin(Integer min) {this.min = min;}public Double getAvg() {return avg;}public void setAvg(Double avg) {this.avg = avg;}
}

student类的编写

package POJO;/*** @program:school* @author: jiage* @Time: 2022/6/14  19:34**/public class Student {//学生学号,数据库自增private Integer ID;//姓名private String name;//性别private String sex;//出生年月日private String dateOfBirth;//学号private String studentID;public Student() {}public Student(Integer ID, String name, String sex, String dateOfBirth, String studentID) {this.ID = ID;this.name = name;this.sex = sex;this.dateOfBirth = dateOfBirth;this.studentID = studentID;}public Integer getID() {return ID;}public void setID(Integer ID) {this.ID = ID;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public String getDateOfBirth() {return dateOfBirth;}public void setDateOfBirth(String dateOfBirth) {this.dateOfBirth = dateOfBirth;}public String getStudentID() {return studentID;}public void setStudentID(String studentID) {this.studentID = studentID;}
}

studentcourse类的编写

package POJO;//学生的课程成绩
public class StudentCourse {//编号private Integer id;//学生名称private String studentName;//课程名称private String courseName;//课程成绩private Integer courseGrade;//学号private String studentID;public StudentCourse() {}public StudentCourse(Integer id, String studentName, String courseName, Integer courseGrade, String studentID) {this.id = id;this.studentName = studentName;this.courseName = courseName;this.courseGrade = courseGrade;this.studentID = studentID;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getStudentName() {return studentName;}public void setStudentName(String studentName) {this.studentName = studentName;}public String getCourseName() {return courseName;}public void setCourseName(String courseName) {this.courseName = courseName;}public Integer getCourseGrade() {return courseGrade;}public void setCourseGrade(Integer courseGrade) {this.courseGrade = courseGrade;}public String getStudentID() {return studentID;}public void setStudentID(String studentID) {this.studentID = studentID;}
}

四,view层的编写

AdminView类的编写,负责管理员的选择登陆界面

package View;import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;public class AdminView extends JFrame {public static StudentCourseView studentCourseView = new StudentCourseView();public static StudentView studentView = new StudentView();public AdminView(){super("学生管理系统");getContentPane().setFont(new Font("宋体", Font.PLAIN, 35));this.setBounds(0, 0, 900, 400);this.setLocationRelativeTo(null);// 让窗口在屏幕中间显示this.setResizable(false);getContentPane().setLayout(null);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 用户单击窗口的关闭按钮时程序执行的操作JLabel lblxxx = new JLabel("你好,欢迎使用学生管理系统");lblxxx.setFont(new Font("宋体", Font.PLAIN, 35));lblxxx.setBounds(44, 35, 726, 91);getContentPane().add(lblxxx);JButton button = new JButton("学生信息管理");button.setFont(new Font("宋体", Font.BOLD, 20));button.setBounds(10, 192, 300, 100);button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {studentView.setVisible(true);dispose();}});getContentPane().add(button);JButton button_1 = new JButton("学生成绩管理");button_1.setFont(new Font("宋体", Font.BOLD, 20));button_1.setBounds(500, 192, 300, 100);button_1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {studentCourseView.setVisible(true);dispose();}});getContentPane().add(button_1);}
}

StudentCourseView类的编写

package View;import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;public class AdminView extends JFrame {public static StudentCourseView studentCourseView = new StudentCourseView();public static StudentView studentView = new StudentView();public AdminView(){super("学生管理系统");getContentPane().setFont(new Font("宋体", Font.PLAIN, 35));this.setBounds(0, 0, 900, 400);this.setLocationRelativeTo(null);// 让窗口在屏幕中间显示this.setResizable(false);getContentPane().setLayout(null);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 用户单击窗口的关闭按钮时程序执行的操作JLabel lblxxx = new JLabel("你好,欢迎使用学生管理系统");lblxxx.setFont(new Font("宋体", Font.PLAIN, 35));lblxxx.setBounds(44, 35, 726, 91);getContentPane().add(lblxxx);JButton button = new JButton("学生信息管理");button.setFont(new Font("宋体", Font.BOLD, 20));button.setBounds(10, 192, 300, 100);button.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {studentView.setVisible(true);dispose();}});getContentPane().add(button);JButton button_1 = new JButton("学生成绩管理");button_1.setFont(new Font("宋体", Font.BOLD, 20));button_1.setBounds(500, 192, 300, 100);button_1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {studentCourseView.setVisible(true);dispose();}});getContentPane().add(button_1);}
}

StudentView类的编写
下面展示一些 内联代码片

package View;import Controller.Select;
import Controller.Updata;import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import java.awt.event.*;
import java.io.IOException;
import java.util.Objects;public class StudentView extends JFrame {Select select = new Select();Updata updata = new Updata();private JTable table;DefaultTableModel df;Object[][] data = null;String[] header =  new String[] { "数据编号","学生姓名" ,"性别","出生年月日","学号" };private JTextField searchid;/*** 面板属性*/private JTextField ID;private JTextField name;private JTextField sex;private JTextField dateOfBirth;private JTextField studentID;public StudentView(){super("学生信息管理");data = select.selectStudentAll();this.setBounds(0, 0, 935, 700);this.setLocationRelativeTo(null);// 让窗口在屏幕中间显示this.setResizable(false);getContentPane().setLayout(null);JScrollPane scrollPane = new JScrollPane();scrollPane.setBounds(27, 321, 876, 331);getContentPane().add(scrollPane);//数据版table = new JTable();df = new DefaultTableModel(data,header);table.setModel(df);scrollPane.setViewportView(table);table.addMouseListener(new MouseListener() {@Overridepublic void mouseReleased(MouseEvent e) {// 处理鼠标释放}@Overridepublic void mousePressed(MouseEvent e) {// 处理鼠标按下}@Overridepublic void mouseExited(MouseEvent e) {// 处理鼠标离开}@Overridepublic void mouseEntered(MouseEvent e) {// 处理鼠标移入}public void mouseClicked(MouseEvent e) {// 处理鼠标点击ID.setText(table.getValueAt(table.getSelectedRow(),0).toString());name.setText(table.getValueAt(table.getSelectedRow(),1).toString());sex.setText(table.getValueAt(table.getSelectedRow(),2).toString());dateOfBirth.setText(table.getValueAt(table.getSelectedRow(),3).toString());studentID.setText(table.getValueAt(table.getSelectedRow(),4).toString());}});JPanel panel = new JPanel();panel.setBorder(new TitledBorder(null, "学生信息", TitledBorder.LEADING, TitledBorder.TOP, null, null));panel.setBounds(27, 27, 876, 200);getContentPane().add(panel);panel.setLayout(null);JLabel label = new JLabel("数据编号:");label.setBounds(32, 30, 75, 18);panel.add(label);ID = new JTextField();ID.setBounds(112, 26, 171, 24);panel.add(ID);ID.setEditable(false);ID.setColumns(10);JLabel label_1 = new JLabel("学生姓名:");label_1.setBounds(300, 30, 75, 18);panel.add(label_1);name = new JTextField();name.setBounds(400, 26, 171, 24);panel.add(name);name.setColumns(10);JLabel label_1_1 = new JLabel("学生性别:");label_1_1.setBounds(32, 60, 60, 18);panel.add(label_1_1);sex = new JTextField();sex.setColumns(10);sex.setBounds(112, 60, 171,24);panel.add(sex);JLabel label_1_1_1 = new JLabel("出生年月:");label_1_1_1.setBounds(300, 60, 75, 18);panel.add(label_1_1_1);dateOfBirth = new JTextField();dateOfBirth.setBounds(400, 60, 171, 24);panel.add(dateOfBirth);dateOfBirth.setColumns(10);JLabel label_1_1_1_1 = new JLabel("学生学号:");label_1_1_1_1.setBounds(32, 90, 60, 18);panel.add(label_1_1_1_1);studentID = new JTextField();studentID.setColumns(10);studentID.setBounds(112, 90, 171,24);panel.add(studentID);JPanel panel_1 = new JPanel();panel_1.setBorder(new TitledBorder(null, "条件查询", TitledBorder.LEADING, TitledBorder.TOP, null, null));panel_1.setBounds(27, 240, 531, 68);getContentPane().add(panel_1);JLabel label_5 = new JLabel("学生姓名:");panel_1.add(label_5);searchid = new JTextField();panel_1.add(searchid);searchid.setColumns(10);JButton searchBuut = new JButton("查询");panel_1.add(searchBuut);searchBuut.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {// 处理鼠标点击name.setText("");ID.setText("");dateOfBirth.setText("");sex.setText("");studentID.setText("");String name = searchid.getText();Object[][] data = select.selectStudentByName(name);df.setDataVector(data, header);}});JButton upBuut = new JButton("重置");panel_1.add(upBuut);upBuut.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {// 处理鼠标点击name.setText("");ID.setText("");sex.setText("");dateOfBirth.setText("");searchid.setText("");studentID.setText("");Object[][] data = select.selectStudentAll();df.setDataVector(data, header);}});searchBuut.setIcon(new ImageIcon(Objects.requireNonNull(StudentView.class.getResource(""))));JButton addButt = new JButton("添加");addButt.setBounds(700, 265, 80, 27);getContentPane().add(addButt);addButt.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {String sName = name.getText();String sSex = sex.getText();String sDateOfBirth = dateOfBirth.getText();String sstringID = studentID.getText();String sql = "INSERT INTO  student VALUES(null,'" + sName + "','"+sSex+"','" + sDateOfBirth+ "','" + sstringID+ "')";int reselt = updata.addData(sql);if (reselt > 0) {JOptionPane.showMessageDialog(null, "添加学生信息成功!");} else {JOptionPane.showMessageDialog(null, "添加失败!");}refresh();}});JButton updataButt = new JButton("修改");updataButt.setBounds(559, 265, 100, 27);getContentPane().add(updataButt);updataButt.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {String sName = name.getText();String sSex = sex.getText();String sDateOfBirth = dateOfBirth.getText();String id = ID.getText();String sstringID= studentID.getText();if (sName.equals("") && sSex.equals("") && sDateOfBirth.equals("")) {JOptionPane.showMessageDialog(null, "请填写完整信息!");} else {String sql = "UPDATE student SET `name`='"+sName+"',sex='"+sSex+"',`dateOfBirth`='"+sDateOfBirth+"',`school_id`='"+sstringID+"' WHERE id='"+id+"'";int reselt = updata.addData(sql);if (reselt > 0) {JOptionPane.showMessageDialog(null, "修改信息成功!");} else {JOptionPane.showMessageDialog(null, "添加失败!");}}refresh();}});JButton button_3 = new JButton("删除");button_3.setBounds(800, 265, 100, 27);getContentPane().add(button_3);button_3.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {if (table.getSelectedColumn() < 0) {JOptionPane.showMessageDialog(null, "请选中要删除的数据!");} else {String text = ID.getText();String dsql = "delete from student where id=" + text;int result = updata.addData(dsql);if (result > 0) {JOptionPane.showMessageDialog(null, "删除成功!");Object[][] data = select.selectStudentAll();df.setDataVector(data, header);} else {JOptionPane.showMessageDialog(null, "删除失败!");}}}});this.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {super.windowClosing(e);new AdminView().setVisible(true);}});}public void refresh(){name.setText("");ID.setText("");sex.setText("");dateOfBirth.setText("");searchid.setText("");studentID.setText("");Object[][] data = select.selectStudentAll();df.setDataVector(data, header);}
}

UserLogin类的编写
下面展示一些 内联代码片

package View;import Controller.Select;import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;public class UserLogin extends JFrame{String uid;private static JTextField username;private JTextField password;JCheckBox chckbxNewCheckBox;public UserLogin() {super("学生管理系统后台登陆");Select select = new Select();this.setBounds(0, 0, 600, 350);this.setLocationRelativeTo(null);// 让窗口在屏幕中间显示this.setResizable(false);// 让窗口大小不可改变getContentPane().setLayout(null);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 用户单击窗口的关闭按钮时程序执行的操作this.setIconImage(Toolkit.getDefaultToolkit().getImage(UserLogin.class.getResource("")));JLabel usernameText = new JLabel("账号:");usernameText.setBounds(142, 70, 72, 18);usernameText.setIcon(new ImageIcon(UserLogin.class.getResource("")));getContentPane().add(usernameText);username = new JTextField();username.setBounds(228, 67, 203, 24);getContentPane().add(username);username.setColumns(10);JLabel passwordText = new JLabel("密码:");passwordText.setIcon(new ImageIcon(UserLogin.class.getResource("")));passwordText.setBounds(142, 138, 72, 18);getContentPane().add(passwordText);password = new JPasswordField();password.setColumns(10);password.setBounds(228, 135, 203, 24);getContentPane().add(password);JButton logButton = new JButton("登录");logButton.setIcon(new ImageIcon(UserLogin.class.getResource("")));logButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {String uname = username.getText();String pwd = password.getText();if (uname.equals("") && pwd.equals("")) {JOptionPane.showMessageDialog(null, "账户名或密码未填写!");} else {//核心判断语句String sql = "select COUNT(*) from admin where username='" + uname + "' and password='" + pwd+ "'";int reselt = select.userloginSelect(sql);if (reselt > 0) {JOptionPane.showMessageDialog(null, "登录成功!欢迎使用!");new AdminView().setVisible(true);dispose();} else {JOptionPane.showMessageDialog(null, "登录失败!账户名或密码不正确!请重新输入!");}}}});logButton.setBounds(318, 228, 113, 27);getContentPane().add(logButton);JButton regButton = new JButton("重置");regButton.setIcon(new ImageIcon(UserLogin.class.getResource("")));regButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {username.setText("");password.setText("");}});regButton.setBounds(142, 228, 113, 27);getContentPane().add(regButton);}//	public static String getUsername() {
//		if (username.getText().equals("")) {
//			return username.getText();
//		}
//		return "系统管理员";
//	}public static void main(String[] args) {new UserLogin().setVisible(true);}}

五,数据库的连接

utils包下的DbConnection类代码如下

package Utils;import javax.swing.*;
import java.sql.*;public class DbConnection {// 驱动类的类名private static final String DRIVERNAME = "com.mysql.cj.jdbc.Driver";// 连接数据的URL路径private static final String URL = "jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false";// 数据库登录账号private static final String USER = "root";// 数据库登录密码private static final String PASSWORD = "yuyue123";// 加载驱动static {try {Class.forName(DRIVERNAME);} catch (ClassNotFoundException e) {e.printStackTrace();}}// 获取数据库连接public static Connection getConnection() {try {return DriverManager.getConnection(URL, USER, PASSWORD);} catch (SQLException e) {e.printStackTrace();}return null;}// 查询public static ResultSet query(String sql) {System.out.println(sql);// 获取连接Connection connection = getConnection();PreparedStatement psd;try {psd = connection.prepareStatement(sql);return psd.executeQuery();} catch (SQLException e) {JOptionPane.showMessageDialog(null, "执行语句出错\n" + e.toString());e.printStackTrace();}return null;}// 增、删、改、查public static int updataInfo(String sql) {System.out.println(sql);// 获取连接Connection connection = getConnection();try {PreparedStatement psd = connection.prepareStatement(sql);return psd.executeUpdate();} catch (SQLException e) {JOptionPane.showMessageDialog(null, "执行语句出错\n" + e.toString());e.printStackTrace();}return 0;}// 关闭连接public static void colse(ResultSet rs, PreparedStatement stmt, Connection conn) throws Exception {try {if (rs != null) {rs.close();}if (stmt != null) {stmt.cancel();}if (conn != null) {conn.close();}} catch (Exception e) {e.printStackTrace();throw new Exception();}}public static void main(String[] args) {}
}

六,启动程序

package Main;import View.UserLogin;public class DoMain {public static void main(String[] args) {new UserLogin().setVisible(true);}
}

写的比较草率,等课设答辩完会仔细修稿。


http://chatgpt.dhexx.cn/article/19Z8Ngvn.shtml

相关文章

Java——学生管理系统

学生管理系统实现步骤&#xff1a; 定义学生类学生管理系统的主界面的代码编写学生管理系统的查看所有学生的代码编写学生管理系统的添加学生代码的编写学生管理系统的删除学生的代码编写学生管理系统的修改学生的代码编写 学生系统主界面&#xff1a; public class Student…

Java学生管理系统设计与实现 (超详细,含课程设计)

最新文章出炉&#xff0c;欢迎点评 它曾是浏览器的王者&#xff0c;如今却前景堪忧...... 推荐阅读 ★★★★ 往期文章回顾&#xff1a; 1、Java开发岗位面试题汇总&#xff08;不断补充……&#xff09;★★★ 2、Java程序员必须掌握的英语词组 ★★ 3、学习Java的9张思…

用Java实现学生管理系统【简化版】基础

&#x1f389;博客首页&#xff1a;痛而不言笑而不语的浅伤 &#x1f4e2;欢迎关注&#x1f973;点赞 &#x1f44d; 收藏 ⭐留言 &#x1f4dd; 欢迎讨论&#xff01; &#x1f52e;本文由痛而不言笑而不语的浅伤原创&#xff0c;CSDN首发&#xff01; &#x1f30b;系列专栏&…

java 学生信息管理系统

只设计了一部分 全部的太多了。会慢慢更新增加。 学生信息管理包括添加&#xff0c;删除&#xff0c;修改&#xff0c;查询&#xff0c;显示全部等 具体结构如图 在SQL Server 2005数据库上实现数据操作。使用纯面向对象的java语言作为开发语言 在sql server 2005新建一个名…

基于java的学生成绩管理系统

本管理系统具有以下功能&#xff1a; 1、学生功能&#xff1a;个人信息查询、修改&#xff1b;成绩查询&#xff1b;修改密码  2、教师功能&#xff1a;学生信息查询&#xff1b;打分&#xff1b;个人信息查询、修改&#xff0c;修改密码  3、管理员功能&#xff1a;教师信…

Java简单学生管理系统

学习了一段时间了。是时候写一个程序来检验一下学习的成果了。 七夕让我们一起new对象。 ok&#xff0c;首先我们来看一下需求。 简单的学生信息管理系统&#xff0c;通过键盘选择操作进行添加学生&#xff08;学号&#xff0c;姓名&#xff0c;性别&#xff0c;年龄&#x…

用Java实现学生管理系统(附项目详细的介绍和源代码)

前言&#xff1a;最近练习了用Java语言实现简单的学生管理系统小项目&#xff0c;分享一下。 Ps&#xff1a;原创不易&#xff0c;请多多支持&#xff01; 摘要分析如下&#xff1a; 实现的主要功能&#xff1a; 1&#xff0c;添加学生信息。 2&#xff0c;查询学生信息(实现…

Java设计学生成绩管理系统

1.1 题目与要求 设计一个学生成绩排名系统 实现以下功能&#xff1a; (1) 具备对成绩的管理功能&#xff08;添加、删除、排序&#xff09;&#xff1b; (2) 具备对成绩的统计功能&#xff08;最高分&#xff0c;最低分&#xff0c;平均分&#xff0c;及格率等&#xff09;…

Java 学生成绩管理系统

教学管理系统很适合初学者对于所学语言的练习。本文是javaSE 中用文件流写的&#xff0c;这个也可以用数据库写。 分析 这个项目有 1.学生 2.老师 3.教务人员 4.管理员四个角色分别担任不同的任务。 1.学生 有属性 id, 密码&#xff0c;性别&#xff0c;年龄&#xff0c;和一…

Java基础——学生管理系统

用内存存储学生信息。(采用集合的方式&#xff09; 步骤&#xff1a; A. 定义学生类 B. 学生管理系统的主界面的代码编写 C. 学生管理系统的查看所有学生的代码编写 D. 学生管理系统的添加学生的代码编写 E. 学生管理系统的删除学生的代码编写 F. 学生管理系统的修改学生的代码…

学生管理系统(Java版)

学生管理系统&#xff08;Java版&#xff09; 前言&#xff1a;这个是大二做的课设&#xff08;还是学生管理系统…&#xff09;&#xff0c;理论上虽然是4个人一组一起做的&#xff0c;但是&#xff0c;注意这个“但是”&#xff0c;还是我一个人承担了所有…代码和文档基本都…

Java 版学生成绩管理系统,附源码

前言 对于计算机专业的学生来讲&#xff0c;一定对于学生成绩管理系统课程设计十分印象深刻。设计、上机、编码、写报告、答辩等一系列流程&#xff0c;虽然很简单&#xff0c;但也可以综合运用我们所学的一些知识了。 今天就来复习以下这个课题&#xff0c;用 Java SE 来实现…

用Java实现一个学生管理系统(附源码)

目录 一、题目要求 二、设计思路 &#xff08;2&#xff09;代表课程的类——Course类 &#xff08;3&#xff09;具体功能实现类——Function类 &#xff08;4&#xff09;测试类——Test类 三、代码实现 &#xff08;1&#xff09;Student.java文件 &#xff08;2&…

Java实现学生管理系统(完整代码)

案例需求 完成一个综合案例&#xff1a;学生管理系统&#xff01;该系统主要功能如下&#xff1a; 添加学生&#xff1a;通过键盘录入学生信息&#xff0c;添加到集合中 删除学生&#xff1a;通过键盘录入要删除学生的学号&#xff0c;将该学生对象从集合中删除 修改学生&…

Java学生信息管理系统

一、选题设计思想 学生信息管理系统是典型的信息管理系统(MIS)&#xff0c;其开发主要包括后台数据库的建立和维护以及前端应用程序的开发。对于前者要求建立起数据一致性和完整性强、安全性高的数据库&#xff1b;对于后者则要求应用程序具有功能完备、易使用、易维护等特点。…

学生管理系统(Java实现)

一、学生信息管理程序 基本要求&#xff1a; 1&#xff0e;要求实现学生信息的使用添加、查找、删除、修改等几个功能&#xff0c;每个功能模块均能实现从模块中退出&#xff0c;从而完成一个学生管理系统所需功能。 2&#xff0e;要使用结构体来实现对学生信息的存储。 3&am…

【JAVA】学生信息管理系统

目录 前言 一、环境搭建 二、功能实现 1.学生信息类的创建 2.学生信息的添加功能 3.学生信息的删除功能 4.学生信息的修改功能 5.学生信息的查看功能 三、主类的调用 1.界面的搭建 2.学生端和教师端 3.系统和功能的选择 总结 前言 JAVA实现的学生信息管理…

Java 学生管理系统(详解)

文章目录 学生类main方法首界面登录功能选择界面添加学生信息删除学生信息修改学生信息查看学生信息 学号遍历 和 清空控制台方法附&#xff1a;学生管理系统代码Student .JavaMain.JavaFunctionModule.javaExtents.Java 总结 下面会分享我在做这个练习时的一些方法以及程序代码…

【超详细】Java实现学生信息管理系统

项目介绍&#xff1a;用java实现学生信息的管理&#xff0c;其中录入的数据包括&#xff1a;学号、姓名、年龄、居住地等&#xff0c;并且能够实现对学生信息的添加、修改、删除、查看功能。 一、创建项目 1、项目名称&#xff1a;myStudentManager 二、创建包 1、包名称&a…

基于JAVA实现的简易学生信息管理系统(附源码)

一、前言 最近在学习JAVA&#xff0c;这几天跟着网上的视频学完基础知识之后&#xff0c;做了一个学生信息管理系统&#xff0c;写的比较普通&#xff0c;没太大亮点&#xff0c;希望可以给初学者一些参考经验&#xff0c;另外&#xff0c;如有不恰当的地方还请各位指正&am…