拿到题目从早上十点肝到晚上十点半,千行代码,第二天继续完善一些功能,变量名都不知道啥意思了😭,没写注释,又花了好长时间看了一遍代码,下面讲解一下如何实现的吧!
新生报到系统
背景:
通过对新生报到流程中的各个环节进行数据记录、编辑、分析,从而更好为该工作服务。新生报到数据一直是困扰着各大高校的管理性问题,人数多、工作量大,这无疑是一个挑战,也因此加快了高校的信息化建设步伐。随着互联网的普及与发展,日常生活中人们接触到的数据正以惊人的速度增长。数据已经成为人们生活中必不可少的事务,随着学校数量和规模的不断扩大,各高校招生人数不断增加,有关学生报到的各种信息也极剧增加。为了更加清晰有效地传达与沟通学生的数据信息,借助于可视化的图形手段。将新生的信息汇总分析,用图像呈现出来。将固有的数据进行可视化分析,来构建独有的数据呈现。面对庞大的数据信息量,就需要设计一个新生报到数据可视化分析系统来提高学生管理工作的效率。通过这样的系统,可以做到数据的规范管理、科学统计和快速的查询,从而减少管理方面的工作量。“新生报到数据可视化分析系统”旨在对新生报道数据进行全面、立体、多维度的管理和统计分析。主要包括前端、后台,主要内容有学生报道信息管理,挖掘统计、后台服务、系统安全。
要求:
(1) 新生注册:本系统仅限已报到学生进行注册,并且在输入用户名时,必须使用本人的真实姓名,在输入密码时,会对密码进行再次确认。
(2) 登录:登录分为管理员登录和学生登录,管理员登录时使用自己的用户名和密码,学生登录时,使用学号进行登录。
(3) 查询(管理员):当输入框为空时,可查询到所有学生的个人信息、报到信息、注册信息,输入学号后,可进行精确查找。
(4) 删除(管理员):在删除学生的个人信息时,若该学生已报到或已注册,提示先删除其报到信息或注册信息;在删除学生的报到信息时,若该学生已注册,提示先删除其的注册信息。
(5) 修改(管理员):可修改学生的部分个人信息、重置学生密码、向报到表中插入其报到时间、更新缴费情况,在宿舍管理时,可查询到所有宿舍、男生宿舍、女生宿舍的信息,修改学生的宿舍情况。
(6) 数据统计:统计新生人数、已报到人数、男生人数、女生人数、已缴费人数、已安排宿舍人数。
(7) 学生登录:登录后默认显示新生的个人信息和报到信息,个人信息仅可对联系电话进行修改,也可进行密码修改。
难度:★★★★
首先根据题目要求我在SQL server2012数据库school中构建了五个表,分别是以下内容:
管理员表:
管理员表为管理员登陆所使用的账号和密码。
新生注册表:
新生注册表为新生报道时注册账号所使用的表
学生登陆表:
学生登陆表为学生登录该系统查询个人信息所使用的表,新生注册信息会同时导入到新生注册表和学生登陆表
学生个人信息表:
学生个人信息表为学生查询自己信息,管理员查询所有学生信息所使用的表。
学生住宿情况:
学生住宿情况表中放置学生所居住的宿舍。
以下为JAVA实现用户图形界面的内容:
首先我们需要安装JDBC,详细内容见
https://blog.csdn.net/m0_64642912/article/details/134885107?spm=1001.2014.3001.5501
首先我们需要新建一个记事本,存放JDBC驱动信息:
然后我们可以使用BufferedReader的readLine()方法读取其内容,这样可以无需每次都填写驱动信息。下面展示JAVA代码:
Login类,该类为主类,实现了登陆界面:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
public class Login extends JFrame implements ActionListener {
public JTextField tf1 = new JTextField();
public static void main(String args[]) {
new Login();
}
public Login() {
this.setSize(500, 500);
this.setTitle("登陆界面");
this.setLayout(null);
this.setVisible(true);
this.setLocation(300, 300);
JLabel lb1 = new JLabel();
JLabel lb2 = new JLabel();
JLabel lb3 = new JLabel();
JLabel lb4 = new JLabel();
JLabel lb5 = new JLabel();
//JTextField tf1 = new JTextField();
JTextField tf2 = new JTextField();
JButton btn1 = new JButton();
JButton btn2 = new JButton();
JButton btn3 = new JButton();
JLabel countLabel = new JLabel();
JLabel maleCountLabel = new JLabel();
JLabel femaleCountLabel = new JLabel();
JLabel paidCountLabel = new JLabel();
JLabel assignedDormCountLabel = new JLabel();
JButton btn4=new JButton("统计");
lb1.setFont(new Font("黑体", Font.PLAIN, 20));
lb2.setFont(new Font("黑体", Font.PLAIN, 20));
lb3.setFont(new Font("黑体", Font.PLAIN, 30));
lb4.setFont(new Font("黑体", Font.PLAIN, 15));
lb5.setFont(new Font("黑体", Font.PLAIN, 20));
tf1.setFont(new Font("黑体", Font.PLAIN, 15));
tf2.setFont(new Font("黑体", Font.PLAIN, 15));
btn1.setFont(new Font("黑体", Font.PLAIN, 15));
btn2.setFont(new Font("黑体", Font.PLAIN, 15));
btn3.setFont(new Font("黑体", Font.PLAIN, 15));
btn4.setFont(new Font("黑体", Font.PLAIN, 15));
lb1.setBounds(10, 80, 100, 30);
lb2.setBounds(10, 120, 100, 30);
lb3.setBounds(150, 10, 200, 40);
lb4.setBounds(135, 55, 230, 20);
lb5.setBounds(200,190,200,30);
tf1.setBounds(120, 80, 300, 30);
tf2.setBounds(120, 120, 300, 30);
btn1.setBounds(100, 155, 125, 30);
btn2.setBounds(230, 155, 100, 30);
btn3.setBounds(335, 155, 100, 30);
btn4.setBounds(10,190,100,30);
countLabel.setBounds(10, 250, 200, 30);
maleCountLabel.setBounds(10, 290, 200, 30);
femaleCountLabel.setBounds(10, 330, 200, 30);
paidCountLabel.setBounds(10, 370, 200, 30);
assignedDormCountLabel.setBounds(10, 410, 200, 30);
lb1.setText("用户名");
lb2.setText("密码");
lb3.setText("新生报道系统");
lb4.setText("大数据1211狄诗琪2021122428");
btn1.setText("管理员登录");
btn2.setText("学生登录");
btn3.setText("新生注册");
btn4.setText("数据统计");
/* countLabel.setText("已报到人数: " + totalRegistered);
maleCountLabel.setText("男生人数: " + maleCount);
femaleCountLabel.setText("女生人数: " + femaleCount);
paidCountLabel.setText("已缴费人数: " + paidCount);
assignedDormCountLabel.setText("已安排宿舍人数: " + assignedDormCount);
*/
this.add(lb1);
this.add(lb2);
this.add(lb3);
this.add(lb4);
this.add(tf1);
this.add(tf2);
this.add(btn1);
this.add(btn2);
this.add(btn3);
this.add(lb5);
this.add(countLabel);
this.add(maleCountLabel);
this.add(femaleCountLabel);
this.add(paidCountLabel);
this.add(assignedDormCountLabel);
this.add(btn4);
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
BufferedReader bfr = new BufferedReader(new FileReader("C:\\Users\\27734\\Desktop\\driver.txt"));
String drivername = bfr.readLine();
String url = bfr.readLine();
String username = bfr.readLine();
String password = bfr.readLine();
Class.forName(drivername);
Connection con = DriverManager.getConnection(url, username, password);
String str1 = tf1.getText();
String str2 = tf2.getText();
PreparedStatement ps = con.prepareStatement("select 密码 from 管理员表 where 用户名 = ?");
ps.setString(1, str1);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
String dbPassword = rs.getString("密码");
if (str2.equals(dbPassword)) {
lb5.setText("登陆成功");
new Admin();
} else {
lb5.setText("密码错误");
}
} else {
lb5.setText("用户名不存在");
}
rs.close();
ps.close();
con.close();
} catch (Exception ex) {}
}
});
btn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
BufferedReader bfr = new BufferedReader(new FileReader("C:\\Users\\27734\\Desktop\\driver.txt"));
String drivername = bfr.readLine();
String url = bfr.readLine();
String username = bfr.readLine();
String password = bfr.readLine();
Class.forName(drivername);
Connection con = DriverManager.getConnection(url, username, password);
String str1 = tf1.getText();
String str2 = tf2.getText();
PreparedStatement ps = con.prepareStatement("select 密码 from 学生登录表 where 学号 = ?");
ps.setString(1, str1);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
String dbPassword = rs.getString("密码");
if (str2.equals(dbPassword)) {
lb5.setText("登录成功");
new Student();
} else {
lb5.setText("密码错误");
}
} else {
lb5.setText("该学生不存在");
}
rs.close();
ps.close();
con.close();
} catch (Exception ex) {}
}
});
btn3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Register();
}
});
btn4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
BufferedReader bfr = new BufferedReader(new FileReader("C:\\Users\\27734\\Desktop\\driver.txt"));
String drivername = bfr.readLine();
String url = bfr.readLine();
String username = bfr.readLine();
String password = bfr.readLine();
Class.forName(drivername);
Connection con = DriverManager.getConnection(url, username, password);
PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) AS total_rows FROM 学生住宿情况 WHERE 住宿情况 IS NOT NULL");
int rowCount = 0;
ResultSet rs = ps.executeQuery();
if (rs.next()) {
rowCount = rs.getInt("total_rows");
}
// 更新标签的文本
assignedDormCountLabel.setText("已分配宿舍人数: " + rowCount);
rs.close();
ps.close();
PreparedStatement ps1 = con.prepareStatement("SELECT COUNT(*) AS total_rows1 FROM 新生注册表");
int rowCount1 = 0;
ResultSet rs1 = ps1.executeQuery();
if (rs1.next()) {
rowCount1 = rs1.getInt("total_rows1");
}
// 更新标签的文本
countLabel.setText("已报道人数: " + rowCount1);
PreparedStatement ps2 = con.prepareStatement("SELECT COUNT(*) AS total_rows2 FROM 学生个人信息表 where 性别='男'");
int rowCount2 = 0;
ResultSet rs2 = ps2.executeQuery();
if (rs2.next()) {
rowCount2 = rs2.getInt("total_rows2");
}
// 更新标签的文本
maleCountLabel.setText("男生人数: " + rowCount2);
PreparedStatement ps3 = con.prepareStatement("SELECT COUNT(*) AS total_rows3 FROM 学生个人信息表 where 性别='女'");
int rowCount3 = 0;
ResultSet rs3 = ps3.executeQuery();
if (rs3.next()) {
rowCount3 = rs3.getInt("total_rows3");
}
// 更新标签的文本
femaleCountLabel.setText("女生人数: " + rowCount3);
PreparedStatement ps4 = con.prepareStatement("SELECT COUNT(*) AS total_rows4 FROM 新生注册表 where 是否缴费='是'");
int rowCount4 = 0;
ResultSet rs4 = ps4.executeQuery();
if (rs4.next()) {
rowCount4 = rs4.getInt("total_rows4");
}
// 更新标签的文本
paidCountLabel.setText("已缴费人数: " + rowCount4);
ps1.close();
ps2.close();
ps3.close();
ps4.close();
rs1.close();
rs2.close();
rs3.close();
rs4.close();
con.close();
} catch (Exception ex) {}
}
});
}
public String getStudentID() {
return tf1.getText();
}
public void actionPerformed(ActionEvent e) {
}
}
在该类中,我们设置了管理员登录按钮对应管理员表,学生登录按钮对应学生登录表,新生注册按钮对应新生注册表和学生登录表,学生注册后,两个表会同时更新学生登录信息,数据统计为已报道人数,男生人数,女生人数,已缴费人数和已分配宿舍人数。
以下为该类的各项时间监听:
点击数据统计按钮:
点击管理员登录后:
若密码错误,则提示密码错误:
若账号错误,则提示用户名不存在:
学生登录按钮:
点击该按钮,学生会进入到插叙系统,需要再次验证个人学号和密码,若用户名或者密码错误同样会提示用户名不存在和密码错误。
点击新生注册按钮:
则会进入到注册页面,新生可在次进行信息的注册。
下面我们先看新生注册页面的Register类:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
import java.time.*;
import java.time.format.*;
public class Register extends JFrame implements ActionListener {
public Register() {
this.setSize(500, 500);
this.setTitle("新生注册");
this.setLayout(null);
this.setVisible(true);
this.setLocation(300, 300);
JLabel lb1 = new JLabel();
JLabel lb2 = new JLabel();
JLabel lb3 = new JLabel();
JLabel lb4 = new JLabel();
JLabel lb5 = new JLabel();
JTextField txt1=new JTextField();
JTextField txt2=new JTextField();
JTextField txt3=new JTextField();
JButton btn1 = new JButton();
lb1.setFont(new Font("黑体", Font.PLAIN, 20));
lb2.setFont(new Font("黑体", Font.PLAIN, 20));
lb3.setFont(new Font("黑体", Font.PLAIN, 30));
lb4.setFont(new Font("黑体", Font.PLAIN, 20));
lb5.setFont(new Font("黑体", Font.PLAIN, 15));
txt1.setFont(new Font("黑体", Font.PLAIN, 15));
txt2.setFont(new Font("黑体", Font.PLAIN, 15));
txt3.setFont(new Font("黑体", Font.PLAIN, 15));
btn1.setFont(new Font("黑体", Font.PLAIN, 15));
lb1.setBounds(10, 55, 100, 30);
lb2.setBounds(10, 90, 100, 30);
lb3.setBounds(175,10, 200, 40);
lb4.setBounds(10,125,100,30);
txt1.setBounds(115,55,300,30);
txt2.setBounds(115,90,300,30);
txt3.setBounds(115,125,300,30);
btn1.setBounds(300,160,100,30);
lb5.setBounds(100,160,195,30);
lb1.setText("学号");
lb2.setText("密码");
lb3.setText("新生注册");
lb4.setText("确认密码");
btn1.setText("注册");
this.add(lb1);
this.add(lb2);
this.add(lb3);
this.add(txt1);
this.add(txt2);
this.add(lb4);
this.add(txt3);
this.add(btn1);
this.add(lb5);
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String str1 = txt1.getText();
String str2 = txt2.getText();
String str3 = txt3.getText();
LocalDate currentDate = LocalDate.now();
String dateString = currentDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
if(str2.equals(str3))
{
try {
BufferedReader bfr = new BufferedReader(new FileReader("C:\\Users\\27734\\Desktop\\driver.txt"));
String drivername = bfr.readLine();
String url = bfr.readLine();
String username = bfr.readLine();
String password = bfr.readLine();
Class.forName(drivername);
Connection con = DriverManager.getConnection(url, username, password);
PreparedStatement ps = con.prepareStatement("insert into 新生注册表(学号,密码,注册时间) values(?,?,?);");
ps.setString(1,str1);
ps.setString(2,str2);
ps.setString(3,dateString);
ps.executeUpdate();
lb5.setText("注册成功");
ps.close();
PreparedStatement ps1 =con.prepareStatement("insert into 学生登录表(学号,密码) values(?,?);");
ps1.setString(1,str1);
ps1.setString(2,str2);
ps1.executeUpdate();
ps1.close();
con.close();
} catch (Exception ex) {}
}else{
lb5.setText("密码错误");
}
}
});
}
public void actionPerformed(ActionEvent e) {
}
}
在该类中,学生需要输入用户名和密码以及确认密码,数据库会更新新生注册表和学生登陆表内容。若两次输入的密码不一样,则提示密码错误并且不会将信息更新到数据库。
当我们正确注册信息后,则提示注册成功并且将该条记录传输到数据库
下面展示Student类:
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.io.*;
import java.sql.*;
import java.awt.event.*;
public class Student extends JFrame implements ActionListener{
private JTable table;
public Student() {
this.setSize(500, 500);
this.setTitle("学生个人信息");
this.setLayout(null);
this.setLocation(300, 300);
this.setVisible(true);
JTextField tf1=new JTextField();
JTextField tf2=new JTextField();
JLabel ll1=new JLabel("学号验证");
JLabel ll2=new JLabel("密码验证");
JLabel ll3=new JLabel();
JButton bt1=new JButton("验证");
ll1.setBounds(10,10,100,25);
ll2.setBounds(10,40,100,25);
ll3.setBounds(300,70,100,20);
tf1.setBounds(115,10,200,25);
tf2.setBounds(115,40,200,25);
bt1.setBounds(115,70,100,30);
this.add(ll1);
this.add(ll2);
this.add(ll3);
this.add(tf1);
this.add(tf2);
this.add(bt1);
//String ID =
JLabel lb1 = new JLabel();
JLabel lb2 = new JLabel();
JTextField txt1 = new JTextField();
JTextField txt2 = new JTextField();
JButton btn1=new JButton();
JButton btn2=new JButton();
lb1.setFont(new Font("黑体", Font.PLAIN, 15));
lb2.setFont(new Font("黑体", Font.PLAIN, 15));
txt1.setFont(new Font("黑体", Font.PLAIN, 15));
txt2.setFont(new Font("黑体", Font.PLAIN, 15));
btn1.setFont(new Font("黑体", Font.PLAIN, 15));
btn2.setFont(new Font("黑体", Font.PLAIN, 15));
lb1.setText("修改密码");
lb2.setText("修改联系电话");
btn1.setText("确认");
btn2.setText("确认");
lb1.setBounds(10, 100, 100, 30);
lb2.setBounds(10, 135, 100, 30);
txt1.setBounds(115, 100, 200, 30);
txt2.setBounds(115, 135, 200, 30);
btn1.setBounds(320,100,100,30);
btn2.setBounds(320,135,100,30);
this.add(lb1);
this.add(lb2);
this.add(txt1);
this.add(txt2);
this.add(btn1);
this.add(btn2);
String[] columnNames = new String[] { "学号", "性别", "姓名", "年龄", "身份证号后八位", "联系电话", "密码" };
DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0);
bt1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
BufferedReader bfr = new BufferedReader(new FileReader("C:\\Users\\27734\\Desktop\\driver.txt"));
String drivername = bfr.readLine();
String url = bfr.readLine();
String username = bfr.readLine();
String password = bfr.readLine();
Class.forName(drivername);
Connection con = DriverManager.getConnection(url, username, password);
String str1 = tf1.getText();
String str2 = tf2.getText();
PreparedStatement ps = con.prepareStatement("select 密码 from 学生登录表 where 学号 = ?");
ps.setString(1, str1);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
String dbPassword = rs.getString("密码");
if (str2.equals(dbPassword)) {
ll3.setText("验证成功");
//new Admin();
try {
String ID = tf1.getText();
PreparedStatement ps1 = con.prepareStatement("select * from 学生个人信息表, 学生登录表 where 学生个人信息表.学号 = ? and 学生登录表.学号 = 学生个人信息表.学号");
ps1.setString(1, ID);
ResultSet rs1 = ps1.executeQuery();
if (rs1.next()) {
String sno = rs1.getString("学号");
String sex = rs1.getString("性别");
String name = rs1.getString("姓名");
String age = rs1.getString("年龄");
String ident = rs1.getString("身份证号后八位");
String number = rs1.getString("联系电话");
String passw = rs1.getString("密码");
String[] rowData = { sno, sex, name, age, ident, number, passw };
tableModel.addRow(rowData);
table = new JTable(tableModel);
JScrollPane sp = new JScrollPane(table);
sp.setFont(new Font("黑体", Font.PLAIN, 15));
sp.setBounds(10,300,450,100);
Student.this.add(sp);
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent c) {
try {
//System.out.println("内层按钮被点击");
String str1 = txt1.getText();
BufferedReader bfr = new BufferedReader(new FileReader("C:\\Users\\27734\\Desktop\\driver.txt"));
String drivername = bfr.readLine();
String url = bfr.readLine();
String username = bfr.readLine();
String password = bfr.readLine();
Class.forName(drivername);
Connection con1 = DriverManager.getConnection(url, username, password);
PreparedStatement ps2= con1.prepareStatement("update 学生登录表 set 密码=? where 学号=?");
//System.out.println("内层按钮被点击");
ps2.setString(1, str1);
ps2.setString(2,ID);
ps2.executeUpdate();
PreparedStatement ps3 = con1.prepareStatement("select * from 学生个人信息表, 学生登录表 where 学生个人信息表.学号 = ? and 学生登录表.学号 = 学生个人信息表.学号");
ps3.setString(1, ID);
ResultSet rs2 = ps3.executeQuery();
if (rs2.next()) {
String sno1 = rs2.getString("学号");
String sex1 = rs2.getString("性别");
String name1 = rs2.getString("姓名");
String age1 = rs2.getString("年龄");
String ident1 = rs2.getString("身份证号后八位");
String number1 = rs2.getString("联系电话");
String passw1 = rs2.getString("密码");
tableModel.setRowCount(0); // 清空表格数据
String[] rowData1 = { sno1, sex1, name1, age1, ident1, number1, passw1};
tableModel.addRow(rowData1);
}
rs1.close();
rs2.close();
ps2.close();
ps3.close();
ps1.close();
con1.close();
} catch (Exception d) {}
}
});
btn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent f) {
try {
String str2 = txt2.getText();
BufferedReader bfr = new BufferedReader(new FileReader("C:\\Users\\27734\\Desktop\\driver.txt"));
String drivername = bfr.readLine();
String url = bfr.readLine();
String username = bfr.readLine();
String password = bfr.readLine();
Class.forName(drivername);
Connection con2 = DriverManager.getConnection(url, username, password);
PreparedStatement psa = con2.prepareStatement("update 学生个人信息表 set 联系电话=? where 学号=?");
psa.setString(1, str2);
psa.setString(2,ID);
psa.executeUpdate();
PreparedStatement psb = con2.prepareStatement("SELECT * FROM 学生个人信息表, 学生登录表 WHERE 学生个人信息表.学号 = ? AND 学生登录表.学号 = 学生个人信息表.学号");
psb.setString(1, ID);
ResultSet rsa = psb.executeQuery();
if (rsa.next()) {
String sno2 = rsa.getString("学号");
String sex2 = rsa.getString("性别");
String name2 = rsa.getString("姓名");
String age2 = rsa.getString("年龄");
String ident2 = rsa.getString("身份证号后八位");
String number2 = rsa.getString("联系电话");
String passw2 = rsa.getString("密码");
tableModel.setRowCount(0); // 清空表格数据
String[] rowData2 = { sno2, sex2, name2, age2, ident2, number2, passw2};
tableModel.addRow(rowData2);
}
rsa.close();
psa.close();
psb.close();
con2.close();
} catch (Exception g) {}
}
});
}
rs1.close();
ps1.close();
ps.close();
} catch (Exception a) {
a.printStackTrace();
}
} else {
ll3.setText("密码错误");
}
} else {
ll3.setText("该用户不存在");
}
con.close();
} catch (Exception exe) {}
}
});
}
public void actionPerformed(ActionEvent e) {
}
}
当我们输入正确的用户名和密码进入到学生登录页面后:
我们需要再次输入本人的学号和密码进行二次认证才能修改密码和联系电话:
错误示范:
正确示范:
下面会显示该学生的个人信息,学生修改密码和联系电话后点击确认按钮表格会同步更新,数据库也会刷新信息。
下面展示管理员类:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
public class Admin extends JFrame implements ActionListener{
public Admin(){
this.setSize(500,300);
this.setTitle("管理员界面");
this.setLayout(null);
this.setVisible(true);
this.setLocation(300, 300);
JButton btn1=new JButton();
JButton btn2=new JButton();
JButton btn3=new JButton();
JButton btn4=new JButton();
btn1.setFont(new Font("黑体", Font.PLAIN, 25));
btn2.setFont(new Font("黑体", Font.PLAIN, 25));
btn3.setFont(new Font("黑体", Font.PLAIN, 25));
btn4.setFont(new Font("黑体", Font.PLAIN, 25));
btn1.setBounds(150,10,200,50);
btn2.setBounds(150,70,200,50);
btn3.setBounds(150,130,200,50);
btn4.setBounds(150,190,200,50);
btn1.setText("添加");
btn2.setText("修改");
btn3.setText("删除");
btn4.setText("查询");
this.add(btn1);
this.add(btn2);
this.add(btn3);
this.add(btn4);
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Add();
}
});
btn2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
new Alter();
}
});
btn3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
new Delete();
}
});
btn4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
new Search();
}
});
}
public void actionPerformed(ActionEvent e) {
}
}
当我们正确进入到管理员界面后:
会显示四个大按钮,为管理员的基本操作——增删改查
下面展示Add类进入添加界面:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
public class Add extends JFrame implements ActionListener{
public Add(){
this.setSize(400,500);
this.setTitle("管理员添加界面");
this.setLayout(null);
this.setVisible(true);
this.setLocation(300, 300);
JLabel lb1=new JLabel();
JLabel lb2=new JLabel();
JLabel lb3=new JLabel();
JLabel lb4=new JLabel();
JLabel lb5=new JLabel();
JLabel lb6=new JLabel();
JLabel lb7=new JLabel();
JLabel lb8=new JLabel();
JTextField txt1=new JTextField();
JTextField txt2=new JTextField();
JTextField txt3=new JTextField();
JTextField txt4=new JTextField();
JTextField txt5=new JTextField();
JTextField txt6=new JTextField();
JTextField txt7=new JTextField();
JButton btn1=new JButton();
lb1.setFont(new Font("黑体", Font.PLAIN, 20));
lb2.setFont(new Font("黑体", Font.PLAIN, 20));
lb3.setFont(new Font("黑体", Font.PLAIN, 20));
lb4.setFont(new Font("黑体", Font.PLAIN, 20));
lb5.setFont(new Font("黑体", Font.PLAIN, 15));
lb6.setFont(new Font("黑体", Font.PLAIN, 20));
lb7.setFont(new Font("黑体", Font.PLAIN, 20));
txt1.setFont(new Font("黑体", Font.PLAIN, 20));
txt2.setFont(new Font("黑体", Font.PLAIN, 20));
txt3.setFont(new Font("黑体", Font.PLAIN, 20));
txt4.setFont(new Font("黑体", Font.PLAIN, 20));
txt5.setFont(new Font("黑体", Font.PLAIN, 20));
txt6.setFont(new Font("黑体", Font.PLAIN, 20));
txt7.setFont(new Font("黑体", Font.PLAIN, 20));
btn1.setFont(new Font("黑体", Font.PLAIN,17));
lb8.setFont(new Font("黑体", Font.PLAIN,20));
lb1.setText("学号");
lb2.setText("性别");
lb3.setText("姓名");
lb4.setText("年龄");
lb5.setText("身份证后八位");
lb6.setText("联系电话");
lb7.setText("宿舍");
btn1.setText("添加");
lb1.setBounds(10,10,100,30);
lb2.setBounds(10,45,100,30);
lb3.setBounds(10,80,100,30);
lb4.setBounds(10,115,100,30);
lb5.setBounds(10,150,100,30);
lb6.setBounds(10,185,100,30);
lb7.setBounds(10,220,100,30);
txt1.setBounds(115,10,200,30);
txt2.setBounds(115,45,200,30);
txt3.setBounds(115,80,200,30);
txt4.setBounds(115,115,200,30);
txt5.setBounds(115,150,200,30);
txt6.setBounds(115,185,200,30);
txt7.setBounds(115,220,200,30);
btn1.setBounds(260,255,110,30);
lb8.setBounds(100,255,150,30);
this.add(lb1);
this.add(lb2);
this.add(lb3);
this.add(lb4);
this.add(lb5);
this.add(lb6);
this.add(lb7);
this.add(txt1);
this.add(txt2);
this.add(txt3);
this.add(txt4);
this.add(txt5);
this.add(txt6);
this.add(txt7);
this.add(btn1);
this.add(lb8);
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
BufferedReader bfr = new BufferedReader(new FileReader("C:\\Users\\27734\\Desktop\\driver.txt"));
String drivername = bfr.readLine();
String url = bfr.readLine();
String username = bfr.readLine();
String password = bfr.readLine();
Class.forName(drivername);
Connection con = DriverManager.getConnection(url, username, password);
String str1 = txt1.getText();
String str2 = txt2.getText();
String str3 = txt3.getText();
String str4 = txt4.getText();
String str5 = txt5.getText();
String str6 = txt6.getText();
String str7 = txt7.getText();
PreparedStatement ps = con.prepareStatement("insert into 学生个人信息表 (学号,性别,姓名,年龄,身份证号后八位,联系电话) values (?,?,?,?,?,?);");
ps.setString(1,str1);
ps.setString(2,str2);
ps.setString(3,str3);
ps.setString(4,str4);
ps.setString(5,str5);
ps.setString(6,str6);
ps.executeUpdate();
ps.close();
PreparedStatement ps1 = con.prepareStatement("insert into 学生住宿情况 (学号,性别,住宿情况) values (?,?,?);");
ps1.setString(1,str1);
ps1.setString(2,str2);
ps1.setString(3,str7);
ps1.executeUpdate();
ps1.close();
con.close();
lb8.setText("添加成功");
} catch (Exception ex) {}
}
});
}
public void actionPerformed(ActionEvent e){}
}
点击添加按钮:
管理员可以添加本校学生信息,比如刚才我们注册了一个学生,学号为2021122488,密码为12345678,但是在我们的学生个人信息表并没有该学生信息,于是我们管理员添加该学生信息:
数据库后台刷新了该学生信息
下面展示修改类Alter进入到修改界面:
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
public class Alter extends JFrame implements ActionListener {
private JTable table;
private JTextField txt1;
public Alter() {
this.setSize(500, 500);
this.setTitle("管理员修改");
this.setLayout(null);
this.setVisible(true);
this.setLocation(300, 300);
JLabel lb1 = new JLabel("学号");
JLabel lb2 = new JLabel("修改选项");
JLabel lb3 = new JLabel("将其修改为");
JButton btn1 = new JButton("查询");
JButton btn2=new JButton("修改");
JTextField txt1 = new JTextField();
JTextField txt2 = new JTextField();
JComboBox<String> cmb=new JComboBox<String>();
lb1.setFont(new Font("黑体", Font.PLAIN, 20));
lb2.setFont(new Font("黑体", Font.PLAIN, 20));
lb3.setFont(new Font("黑体", Font.PLAIN, 20));
txt1.setFont(new Font("黑体", Font.PLAIN, 20));
txt2.setFont(new Font("黑体", Font.PLAIN, 20));
btn1.setFont(new Font("黑体", Font.PLAIN, 20));
btn2.setFont(new Font("黑体", Font.PLAIN, 20));
cmb.setFont(new Font("黑体", Font.PLAIN, 20));
lb1.setBounds(10, 10, 100, 30);
lb2.setBounds(10, 45,100,30);
lb3.setBounds(10,80,100,30);
txt1.setBounds(115, 10, 200, 30);
txt2.setBounds(115,80,200,30);
btn1.setBounds(320, 10, 100, 30);
btn2.setBounds(320, 80,100,30);
cmb.setBounds(115,45,200,30);
cmb.addItem("性别");
cmb.addItem("姓名");
cmb.addItem("年龄");
cmb.addItem("联系电话");
cmb.addItem("住宿情况");
cmb.addItem("注册时间");
cmb.addItem("是否缴费");
cmb.addItem("重置该学生密码");
// btn1.addActionListener(this);
this.add(lb1);
this.add(txt1);
this.add(btn1);
this.add(cmb);
this.add(lb2);
this.add(lb3);
this.add(txt2);
this.add(btn2);
String[] columnNames = new String[]{"学号", "性别", "姓名", "年龄", "联系电话", "宿舍", "报道时间","缴费情况","密码"};
DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0);
table = new JTable(tableModel);
JScrollPane sp = new JScrollPane(table);
sp.setFont(new Font("黑体", Font.PLAIN, 15));
sp.setBounds(50,300,400,150);
this.add(sp);
btn1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("查询")) {
try {
BufferedReader bfr = new BufferedReader(new FileReader("C:\\Users\\27734\\Desktop\\driver.txt"));
String drivername = bfr.readLine();
String url = bfr.readLine();
String username = bfr.readLine();
String password = bfr.readLine();
bfr.close();
Class.forName(drivername);
Connection con = DriverManager.getConnection(url, username, password);
PreparedStatement ps = con.prepareStatement("select * from 学生个人信息表,新生注册表,学生住宿情况 where 学生个人信息表.学号 = ? and 学生个人信息表.学号=新生注册表.学号 and 学生个人信息表.学号=学生住宿情况.学号");
ps.setString(1, txt1.getText());
ResultSet rs = ps.executeQuery();
DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
tableModel.setRowCount(0); // 清空表格
if (rs.next()) {
String sno = rs.getString("学号");
String sex = rs.getString("性别");
String name = rs.getString("姓名");
String age = rs.getString("年龄");
String number = rs.getString("联系电话");
String dorm = rs.getString("住宿情况");
String tme = rs.getString("注册时间");
String pri= rs.getString("是否缴费");
String passw=rs.getString("密码");
String[] rowData = {sno, sex, name, age, number, dorm, tme,pri,passw};
tableModel.addRow(rowData);
}
rs.close();
ps.close();
con.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
});
btn2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
try {
BufferedReader bfr = new BufferedReader(new FileReader("C:\\Users\\27734\\Desktop\\driver.txt"));
String drivername = bfr.readLine();
String url = bfr.readLine();
String username = bfr.readLine();
String password = bfr.readLine();
bfr.close();
Class.forName(drivername);
Connection con = DriverManager.getConnection(url, username, password);
String str1=(String)cmb.getSelectedItem();
String str2=txt2.getText();
String str3=txt1.getText();
//PreparedStatement ps = con.prepareStatement("UPDATE 学生个人信息表, 新生注册表, 学生住宿情况 SET " + str1 + " = ? WHERE 学生个人信息表.学号 = ? AND 学生个人信息表.学号 = 新生注册表.学号 AND 学生个人信息表.学号 = 学生住宿情况.学号;");
if (str1.equals("学号") || str1.equals("性别") || str1.equals("姓名")||str1.equals("年龄") || str1.equals("联系电话")) {
PreparedStatement ps = con.prepareStatement("UPDATE 学生个人信息表 SET " + str1 + " = ? WHERE 学号 = ?;");
ps.setString(1, str2);
ps.setString(2, str3);
ps.executeUpdate();
ps.close();
}
if (str1.equals("住宿情况")){
PreparedStatement ps = con.prepareStatement("UPDATE 学生住宿情况 SET " + str1 + " = ? WHERE 学号 = ?;");
ps.setString(1, str2);
ps.setString(2, str3);
ps.executeUpdate();
ps.close();
}
if(str1.equals("注册时间")||str1.equals("是否缴费")){
PreparedStatement ps = con.prepareStatement("UPDATE 新生注册表 SET " + str1 + " = ? WHERE 学号 = ?;");
ps.setString(1, str2);
ps.setString(2, str3);
ps.executeUpdate();
ps.close();
}
if (str1.equals("重置该学生密码")){
PreparedStatement ps =con.prepareStatement("UPDATE 新生注册表 SET 密码 = ? WHERE 学号 = ?;");
ps.setString(1, str2);
ps.setString(2, str3);
ps.executeUpdate();
ps.close();
PreparedStatement psx =con.prepareStatement("UPDATE 学生登录表 SET 密码 = ? WHERE 学号 = ?;");
psx.setString(1,str2);
psx.setString(2,str3);
psx.executeUpdate();
psx.close();
}
PreparedStatement ps1 = con.prepareStatement("select * from 学生个人信息表,新生注册表,学生住宿情况 where 学生个人信息表.学号 = ? and 学生个人信息表.学号=新生注册表.学号 and 学生个人信息表.学号=学生住宿情况.学号;");
ps1.setString(1, txt1.getText());
ResultSet rs = ps1.executeQuery();
DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
tableModel.setRowCount(0); // 清空表格
if (rs.next()) {
String sno = rs.getString("学号");
String sex = rs.getString("性别");
String name = rs.getString("姓名");
String age = rs.getString("年龄");
String number = rs.getString("联系电话");
String dorm = rs.getString("住宿情况");
String tme = rs.getString("注册时间");
String pri=rs.getString("是否缴费");
String passw=rs.getString("密码");
String[] rowData = {sno, sex, name, age, number, dorm, tme,pri,passw};
tableModel.addRow(rowData);
}
rs.close();
ps1.close();
con.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
}
public void actionPerformed(ActionEvent e){}
}
点击管理员修改界面按钮,进入到修改界面:
修改选项时一个下拉列表框控件,我们可以修改学生的信息:
比如,此时我们修改学号为2021122488同学的缴费情况:
此时该同学缴费情况栏为空表示未缴费,我们将其改为是:
表中实时更新信息。
下面展示查询界面:
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
public class Search extends JFrame implements ActionListener{
private JTable table;
public Search(){
this.setSize(500, 500);
this.setTitle("管理员查询");
this.setLayout(null);
this.setVisible(true);
this.setLocation(300, 300);
JLabel lb1 = new JLabel("学号");
JButton btn1 = new JButton("查询");
JTextField txt1 = new JTextField();
lb1.setFont(new Font("黑体", Font.PLAIN, 20));
btn1.setFont(new Font("黑体", Font.PLAIN, 20));
txt1.setFont(new Font("黑体", Font.PLAIN, 20));
lb1.setBounds(10,10,100,30);
txt1.setBounds(115,10,200,30);
btn1.setBounds(320,10,100,30);
this.add(lb1);
this.add(btn1);
this.add(txt1);
String[] columnNames = new String[]{"学号", "性别", "姓名", "年龄", "联系电话", "宿舍", "报道时间","缴费情况"};
DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0);
table = new JTable(tableModel);
JScrollPane sp = new JScrollPane(table);
sp.setFont(new Font("黑体", Font.PLAIN, 15));
sp.setBounds(50,300,400,150);
this.add(sp);
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
BufferedReader bfr = new BufferedReader(new FileReader("C:\\Users\\27734\\Desktop\\driver.txt"));
String drivername = bfr.readLine();
String url = bfr.readLine();
String username = bfr.readLine();
String password = bfr.readLine();
bfr.close();
Class.forName(drivername);
Connection con = DriverManager.getConnection(url, username, password);
String studentId = txt1.getText().trim();
if (studentId.isEmpty()) {
// 查询所有学生的信息
PreparedStatement ps = con.prepareStatement("SELECT * FROM 学生个人信息表, 新生注册表, 学生住宿情况 WHERE 学生个人信息表.学号 = 新生注册表.学号 AND 学生个人信息表.学号 = 学生住宿情况.学号 ");
ResultSet rs = ps.executeQuery();
// 处理查询结果,并显示在JTable中
DefaultTableModel model = new DefaultTableModel();
table.setModel(model);
// 添加列名
model.addColumn("学号");
model.addColumn("性别");
model.addColumn("姓名");
model.addColumn("年龄");
model.addColumn("联系电话");
model.addColumn("宿舍");
model.addColumn("报道时间");
model.addColumn("缴费情况");
// 添加数据行
while (rs.next()) {
model.addRow(new Object[]{
rs.getString("学号"),
rs.getString("性别"),
rs.getString("姓名"),
rs.getString("年龄"),
rs.getString("联系电话"),
rs.getString("住宿情况"),
rs.getString("注册时间"),
rs.getString("是否缴费")
});
}
rs.close();
ps.close();
} else {
// 根据学号进行精确查找
PreparedStatement ps = con.prepareStatement("SELECT * FROM 学生个人信息表, 新生注册表, 学生住宿情况 WHERE 学生个人信息表.学号 = ? AND 学生个人信息表.学号 = 新生注册表.学号 AND 学生个人信息表.学号 = 学生住宿情况.学号");
ps.setString(1, studentId);
ResultSet rs = ps.executeQuery();
// 处理查询结果,并显示在JTable中
DefaultTableModel model = new DefaultTableModel();
table.setModel(model);
// 添加列名
model.addColumn("学号");
model.addColumn("性别");
model.addColumn("姓名");
model.addColumn("年龄");
model.addColumn("联系电话");
model.addColumn("宿舍");
model.addColumn("报道时间");
model.addColumn("缴费情况");
// 添加数据行
while (rs.next()) {
model.addRow(new Object[]{
rs.getString("学号"),
rs.getString("性别"),
rs.getString("姓名"),
rs.getString("年龄"),
rs.getString("联系电话"),
rs.getString("住宿情况"),
rs.getString("注册时间"),
rs.getString("是否缴费")
});
}
rs.close();
ps.close();
}
con.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
}
public void actionPerformed(ActionEvent e) {}
}
该界面为管理员查询所有同学信息的界面:
当我们未输入学号直接点击查询按钮时,显示数据库中所有学生信息:
当我们精准查找信息时,输入学号再点击按钮即可:
最后我们展示删除界面:
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
public class Delete extends JFrame implements ActionListener{
private JTable table;
public Delete(){
this.setSize(500, 500);
this.setTitle("管理员删除");
this.setLayout(null);
this.setVisible(true);
this.setLocation(300, 300);
JLabel lb1 = new JLabel();
JTextField txt1 = new JTextField();
JButton btn1 = new JButton();
JButton btn2 =new JButton();
lb1.setFont(new Font("黑体", Font.PLAIN, 20));
txt1.setFont(new Font("黑体", Font.PLAIN, 20));
btn1.setFont(new Font("黑体", Font.PLAIN, 20));
btn2.setFont(new Font("黑体", Font.PLAIN, 20));
lb1.setText("学号");
btn1.setText("查询");
btn2.setText("删除");
lb1.setBounds(10,10,100,30);
txt1.setBounds(115,10,200,30);
btn1.setBounds(320,10,100,30);
btn2.setBounds(320,45,100,30);
String[] columnNames = new String[]{"学号", "性别", "姓名", "年龄", "联系电话", "宿舍", "报道时间"};
DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0);
table = new JTable(tableModel);
JScrollPane sp = new JScrollPane(table);
sp.setFont(new Font("黑体", Font.PLAIN, 15));
sp.setBounds(50,300,400,150);
this.add(sp);
this.add(lb1);
this.add(txt1);
this.add(btn1);
this.add(btn2);
btn1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("查询")) {
try {
BufferedReader bfr = new BufferedReader(new FileReader("C:\\Users\\27734\\Desktop\\driver.txt"));
String drivername = bfr.readLine();
String url = bfr.readLine();
String username = bfr.readLine();
String password = bfr.readLine();
bfr.close();
Class.forName(drivername);
Connection con = DriverManager.getConnection(url, username, password);
PreparedStatement ps = con.prepareStatement("select * from 学生个人信息表,新生注册表,学生住宿情况 where 学生个人信息表.学号 = ? and 学生个人信息表.学号=新生注册表.学号 and 学生个人信息表.学号=学生住宿情况.学号");
ps.setString(1, txt1.getText());
ResultSet rs = ps.executeQuery();
DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
tableModel.setRowCount(0); // 清空表格
if (rs.next()) {
String sno = rs.getString("学号");
String sex = rs.getString("性别");
String name = rs.getString("姓名");
String age = rs.getString("年龄");
String number = rs.getString("联系电话");
String dorm = rs.getString("住宿情况");
String tme = rs.getString("注册时间");
String[] rowData = {sno, sex, name, age, number, dorm, tme};
tableModel.addRow(rowData);
}
rs.close();
ps.close();
con.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
});
btn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
BufferedReader bfr = new BufferedReader(new FileReader("C:\\Users\\27734\\Desktop\\driver.txt"));
String drivername = bfr.readLine();
String url = bfr.readLine();
String username = bfr.readLine();
String password = bfr.readLine();
bfr.close();
Class.forName(drivername);
Connection con = DriverManager.getConnection(url, username, password);
String studentId = txt1.getText();
// 查询学生的注册信息和报到信息
PreparedStatement ps1 = con.prepareStatement("SELECT * FROM 学生个人信息表 WHERE 学号 = ?");
ps1.setString(1, studentId);
ResultSet rs1 = ps1.executeQuery();
PreparedStatement ps2 = con.prepareStatement("SELECT * FROM 新生注册表 WHERE 学号 = ?");
ps2.setString(1, studentId);
ResultSet rs2 = ps2.executeQuery();
// 判断学生是否已报到或已注册
boolean isRegistered = rs2.next();
boolean hasPersonalInfo = rs1.next();
if (hasPersonalInfo) {
// 学生有个人信息
if (isRegistered) {
// 学生已注册,提示先删除注册信息
int confirmDeleteRegistration = JOptionPane.showConfirmDialog(null, "该学生已注册,是否先删除注册信息?", "确认删除注册信息", JOptionPane.YES_NO_OPTION);
if (confirmDeleteRegistration == JOptionPane.YES_OPTION) {
// 删除注册信息
PreparedStatement psa = con.prepareStatement("DELETE FROM 新生注册表 WHERE 学号 = ?");
psa.setString(1, studentId);
psa.executeUpdate();
//删除宿舍信息
PreparedStatement psb = con.prepareStatement("DELETE FROM 学生住宿情况 WHERE 学号 = ?");
psb.setString(1, studentId);
psb.executeUpdate();
//删除登录表
PreparedStatement psc = con.prepareStatement("DELETE FROM 学生登录表 WHERE 学号 = ?");
psc.setString(1, studentId);
psc.executeUpdate();
psa.close();
psb.close();
psc.close();
}
} else {
// 学生未注册,直接删除个人信息
int confirmDeletePersonalInfo = JOptionPane.showConfirmDialog(null, "确认删除学生的个人信息?", "确认删除个人信息", JOptionPane.YES_NO_OPTION);
if (confirmDeletePersonalInfo == JOptionPane.YES_OPTION) {
// 删除个人信息
PreparedStatement psDeletePersonalInfo = con.prepareStatement("DELETE FROM 学生个人信息表 WHERE 学号 = ?");
psDeletePersonalInfo.setString(1, studentId);
psDeletePersonalInfo.executeUpdate();
}
}
} else {
// 学生没有个人信息
JOptionPane.showMessageDialog(null, "找不到该学生的个人信息");
}
rs1.close();
rs2.close();
ps1.close();
ps2.close();
con.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
}
public void actionPerformed(ActionEvent e){}
}
首先,管理员需要查询删除学生的个人信息,输入学号:
我们想删除刚刚的吴一同学:
由于他已经注册了信息,所以我们在点击删除按钮时会先提示删除注册信息:
我们点击“是”后,再次点击删除按钮:
我们再次点击“是”则该学生信息就会被删除。
我们再次点击删除按钮:
我们去数据库确认:
该学生信息全部删除!
以上就是本次简易新生报道系统的设计,感谢观看!