学生成绩管理系统

使用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);}
}

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

java学生成绩管理系统相关推荐

  1. java学生成绩管理系统界面设计

    关于学生成绩管理系统的界面设计:代码如下 数据库表设计 DROP TABLE IF EXISTS `student`; CREATE TABLE `student` (`username` varch ...

  2. java学生成绩管理系统(GUI+mysql+排序)

    java编写的学生成绩管理系统,GUI界面+mysql数据库,实现了增删改查.排序和另存的基本功能 输入数据库的用户名和密码就可以直接登录 不用自己建立数据库和表,由程序自动建立! (注:程序自动建立 ...

  3. java学生成绩管理系统类图,学生成绩管理系统的分析及设计-应用UML建模

    <学生成绩管理系统的分析及设计-应用UML建模>由会员分享,可在线阅读,更多相关<学生成绩管理系统的分析及设计-应用UML建模(48页珍藏版)>请在人人文库网上搜索. 1.第1 ...

  4. java学生成绩管理系统类图,学生成绩管理系统的用例类图

    <学生成绩管理系统的用例类图>由会员分享,可在线阅读,更多相关<学生成绩管理系统的用例类图(20页珍藏版)>请在金锄头文库上搜索. 1.学生成绩管理系统,1.用例图绘制 2.活 ...

  5. java学生成绩管理系统,你的毕设我的心

    当年从学校毕业做毕设的时候,网络还没有现在那么普遍,想要找个参考却也不容易,我当时是费了不少功夫才顺利的通过了答辩,所以最近就自己写了一个学生成绩管理系统,希望给做毕设的同学和刚入行做开发不久的同行, ...

  6. 基于Swing的Java学生成绩管理系统

  7. Java学生成绩管理系统(含源码+论文+答辩PPT等)

    该项目采用技术JSP.Servlet.jdbc.Tomcat服务器.MySQL数据库 ,项目含有源码.论文.配套开发软件.软件安装教程.项目发布教程 下面是系统运行起来后的部分截图:

  8. java学生信息管理系统(GUI+mysql数据库)

    java学生信息管理系统+GUI界面布局+mysql数据库 代码已经更新!,重新设计了UI界面,代码之间的逻辑更加清晰 新的代码不需要手动建立数据库和表,全部由程序自动执行 用户名和密码为你数据库的用 ...

  9. java开发的简易学生成绩管理系统

    经过1个月的紧张学习和应用,终于做出了这个简易的学生成绩管理系统. 代码如下(仅供参考学习) view包下的菜单 package com.xujulong.www.view: import java. ...

  10. Java根据学号提取班级_学生成绩管理系统 1. 能够实现根据以下关键字查询:学生姓名 、学号、班级、课 联合开发网 - pudn.com...

    学生成绩管理系统 所属分类:Java编程 开发工具:Java 文件大小:1204KB 下载次数:0 上传日期:2020-12-06 16:50:53 上 传 者:sunyue111 说明:  1. 能 ...

最新文章

  1. 16岁自闭少年被指黑掉英伟达微软,曾赚1400万美元,英国警方逮捕7人
  2. 【c语言】蓝桥杯算法训练 简单加法(基本型)
  3. LeetCode: 20. Valid Parentheses
  4. android RecycleView padding 和高度一样会出现什么情况?
  5. 【转】javascript中的LHS与RHS
  6. BeanUtils组件
  7. Codeforces Round #490 (Div. 3)
  8. SAP Cloud Application Programming 里的@(path) 注解
  9. html 行内超出隐藏,css如何设置文字不换行超出隐藏?
  10. codeforces1167 E. Range Deleting(双指针)
  11. 【附答案】Java面试2019常考题目汇总(一)
  12. linux 递归创建线程,[linux]二叉树的建立及其递归遍历(C语言实现)
  13. 【Spring第一篇】ClassPathXmlApplicationContext工作原理
  14. 如何自动申请京东试用商品、签到获取京豆
  15. 基于单片机的脉搏心率远程监测
  16. C#字符串解析成16进制,并计算校验和
  17. java轿煤悝炾厍桴,最让人放心的汉字笔画序库.doc
  18. Python学习笔记——eofs.standard的使用
  19. html网页打不开二级网页,教你二级网页打不开怎么解决
  20. 【Spring Security】安全框架学习(十三)

热门文章

  1. 快手无水印下载(python小爬虫)
  2. 中控考勤机无线连接不上服务器,中控考勤机安装及常见问题【图解】
  3. Linux - yum安装步骤
  4. 时序数据库 VS 工业实时数据库
  5. 【matlab】人工智能的仿生优化算法之萤火虫算法讲解(Firefly Algorithm)
  6. Python 读取/保存 图片,发现有色差,可以怎么解决了?
  7. python古诗词生成_唐诗生成器
  8. Sql Server 2008完全卸载方法(其他版本类似)
  9. PDF格式的文件该如何转换成PPT
  10. c语言程序设计必备单词,(完整版)C语言编程必背单词.docx