学校一位学弟在我之前写的课设(基于学生信息管理系统的数据库系统课程设计(mysql))基础上做了改进,功能更加细致和完善。
1、执行创建数据库命令(数据库名为q2): create database q2;
2、运行下面的数据库脚本建表。
/*
Navicat MySQL Data Transfer
Source Server : pumpkin
Source Server Version : 50528
Source Host : localhost:3306
Source Database : infodb
Target Server Type : MYSQL
Target Server Version : 50528
File Encoding : 65001
Date: 2021-01-09 16:13:35
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for chang
-- ----------------------------
DROP TABLE IF EXISTS `chang`;
CREATE TABLE `chang` (
`ID` int(11) DEFAULT NULL,
`STUDENTID` int(11) DEFAULT NULL,
`CHAN` int(11) DEFAULT NULL,
`REC_TIME` varchar(15) DEFAULT NULL,
`DSRPIN` varchar(15) DEFAULT NULL,
KEY `SI_SI` (`STUDENTID`),
KEY `chan_code` (`CHAN`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;
-- ----------------------------
-- Records of chang
-- ----------------------------
INSERT INTO `chang` VALUES ('3', '3', '2', '2020/12/31', '复学');
INSERT INTO `chang` VALUES ('4', '4', '5', '2020/12/31', '转学');
INSERT INTO `chang` VALUES ('5', '5', '5', '2020/12/31', '转学');
INSERT INTO `chang` VALUES ('6', '6', '3', '2020/12/30', '退学');
INSERT INTO `chang` VALUES ('7', '7', '4', '2020/12/30', '复学');
INSERT INTO `chang` VALUES ('8', '8', '4', '2020/12/29', '复学');
INSERT INTO `chang` VALUES ('9', '9', '1', '2020/2/28', ' 休学');
INSERT INTO `chang` VALUES ('2', '2', '0', '2020/12/31', '转专业');
INSERT INTO `chang` VALUES ('1', '1', '0', '2020/12/31', '转专业');
INSERT INTO `chang` VALUES ('10', '10', '3', '2020/2/27', '退学');
-- ----------------------------
-- Table structure for change_code
-- ----------------------------
DROP TABLE IF EXISTS `change_code`;
CREATE TABLE `change_code` (
`CODE` int(11) NOT NULL,
`DSRPIN` varchar(15) DEFAULT NULL,
PRIMARY KEY (`CODE`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;
-- ----------------------------
-- Records of change_code
-- ----------------------------
INSERT INTO `change_code` VALUES ('0', '转系');
INSERT INTO `change_code` VALUES ('1', '休学');
INSERT INTO `change_code` VALUES ('2', '复学');
INSERT INTO `change_code` VALUES ('3', '退学');
INSERT INTO `change_code` VALUES ('4', '毕业');
INSERT INTO `change_code` VALUES ('5', '转学');
-- ----------------------------
-- Table structure for class
-- ----------------------------
DROP TABLE IF EXISTS `class`;
CREATE TABLE `class` (
`ID` int(11) NOT NULL,
`NAME` varchar(10) DEFAULT NULL,
`MONITOR` int(11) DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `ID_index` (`ID`),
KEY `MONITOR_SI` (`MONITOR`),
CONSTRAINT `MONITOR_SI` FOREIGN KEY (`MONITOR`) REFERENCES `student` (`STUDENTID`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;
-- ----------------------------
-- Records of class
-- ----------------------------
INSERT INTO `class` VALUES ('1', '一班', null);
INSERT INTO `class` VALUES ('2', '二班', null);
INSERT INTO `class` VALUES ('3', '三班', null);
INSERT INTO `class` VALUES ('4', '四班', null);
INSERT INTO `class` VALUES ('5', '五班', null);
INSERT INTO `class` VALUES ('6', '六班', null);
INSERT INTO `class` VALUES ('7', '七班', null);
-- ----------------------------
-- Table structure for department
-- ----------------------------
DROP TABLE IF EXISTS `department`;
CREATE TABLE `department` (
`ID` int(11) NOT NULL,
`NAME` varchar(10) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;
-- ----------------------------
-- Records of department
-- ----------------------------
INSERT INTO `department` VALUES ('1', '资安');
INSERT INTO `department` VALUES ('2', '土木');
INSERT INTO `department` VALUES ('3', '机电');
INSERT INTO `department` VALUES ('4', '计科');
INSERT INTO `department` VALUES ('5', '化工');
INSERT INTO `department` VALUES ('6', '物电');
INSERT INTO `department` VALUES ('7', '人文');
INSERT INTO `department` VALUES ('8', '外国语');
INSERT INTO `department` VALUES ('9', '马克思');
INSERT INTO `department` VALUES ('10', '体育');
-- ----------------------------
-- Table structure for punishment
-- ----------------------------
DROP TABLE IF EXISTS `punishment`;
CREATE TABLE `punishment` (
`ID` int(11) DEFAULT NULL,
`STUDENTID` int(11) DEFAULT NULL,
`LEVELS` int(11) DEFAULT NULL,
`REC_TIME` varchar(15) DEFAULT NULL,
`ENABLE` varchar(4) DEFAULT NULL,
`DSRPIN` varchar(15) DEFAULT NULL,
KEY `LEVELS_CODETWO` (`LEVELS`),
KEY `SI_SIthree` (`STUDENTID`),
CONSTRAINT `LEVELS_CODETWO` FOREIGN KEY (`LEVELS`) REFERENCES `punish_levels` (`CODE`),
CONSTRAINT `SI_SIthree` FOREIGN KEY (`STUDENTID`) REFERENCES `student` (`STUDENTID`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;
-- ----------------------------
-- Records of punishment
-- ----------------------------
INSERT INTO `punishment` VALUES ('1', '6', '2', '2020/12/30', '是', '非法经营');
INSERT INTO `punishment` VALUES ('2', '9', '2', '2020/12/30', '是', '使用大功率电器');
INSERT INTO `punishment` VALUES ('3', '10', '4', '2020/12/30', '是', '嫖娼');
-- ----------------------------
-- Table structure for punish_levels
-- ----------------------------
DROP TABLE IF EXISTS `punish_levels`;
CREATE TABLE `punish_levels` (
`CODE` int(11) NOT NULL,
`DSRPIN` varchar(15) DEFAULT NULL,
PRIMARY KEY (`CODE`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;
-- ----------------------------
-- Records of punish_levels
-- ----------------------------
INSERT INTO `punish_levels` VALUES ('0', '警告');
INSERT INTO `punish_levels` VALUES ('1', '严重警告');
INSERT INTO `punish_levels` VALUES ('2', '记过');
INSERT INTO `punish_levels` VALUES ('3', '记大过');
INSERT INTO `punish_levels` VALUES ('4', '开除');
-- ----------------------------
-- Table structure for reward
-- ----------------------------
DROP TABLE IF EXISTS `reward`;
CREATE TABLE `reward` (
`ID` int(11) DEFAULT NULL,
`STUDENTID` int(11) DEFAULT NULL,
`LEVELS` int(11) DEFAULT NULL,
`REC_TIME` varchar(15) DEFAULT NULL,
`DSRPIN` varchar(15) DEFAULT NULL,
KEY `LEVELS_CODE` (`LEVELS`),
KEY `SI_SItwo` (`STUDENTID`),
KEY `DSRPIN` (`DSRPIN`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;
-- ----------------------------
-- Records of reward
-- ----------------------------
INSERT INTO `reward` VALUES ('2', '2', '1', '2020/12/30', '校编程比赛');
INSERT INTO `reward` VALUES ('3', '3', '2', '2020/12/30', '一校一书');
INSERT INTO `reward` VALUES ('4', '4', '3', '2020/12/30', '新生写作赛');
INSERT INTO `reward` VALUES ('5', '5', '4', '2020/12/30', '新生才艺赛');
INSERT INTO `reward` VALUES ('6', '7', '6', '2020/12/30', '新生辩论赛');
INSERT INTO `reward` VALUES ('7', '8', '5', '2020/12/30', '新生书画赛');
INSERT INTO `reward` VALUES ('1', '1', '0', '2020/12/30', '发表SCI论文');
-- ----------------------------
-- Table structure for reward_levels
-- ----------------------------
DROP TABLE IF EXISTS `reward_levels`;
CREATE TABLE `reward_levels` (
`CODE` int(11) NOT NULL,
`DSRPIN` varchar(15) DEFAULT NULL,
PRIMARY KEY (`CODE`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;
-- ----------------------------
-- Records of reward_levels
-- ----------------------------
INSERT INTO `reward_levels` VALUES ('0', '校特等奖学金');
INSERT INTO `reward_levels` VALUES ('1', '校一等奖学金');
INSERT INTO `reward_levels` VALUES ('2', '校二等奖学金');
INSERT INTO `reward_levels` VALUES ('3', '校三等奖学金');
INSERT INTO `reward_levels` VALUES ('4', '系一等奖学金');
INSERT INTO `reward_levels` VALUES ('5', '系二等奖学金');
INSERT INTO `reward_levels` VALUES ('6', '系三等奖学金');
-- ----------------------------
-- Table structure for student
-- ----------------------------
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (
`STUDENTID` int(11) NOT NULL,
`NAME` char(10) NOT NULL,
`SEX` char(2) NOT NULL,
`CLASS` int(11) NOT NULL,
`DEPARTMENT` int(11) DEFAULT NULL,
`BIRTHDAY` varchar(15) DEFAULT NULL,
`NATIVE_PLACE` varchar(10) DEFAULT NULL,
PRIMARY KEY (`STUDENTID`),
KEY `SI_C` (`CLASS`),
KEY `department_id` (`DEPARTMENT`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;
-- ----------------------------
-- Records of student
-- ----------------------------
INSERT INTO `student` VALUES ('1', '赵伊', '女', '1', '10', '2001.1.1', '湖南长沙');
INSERT INTO `student` VALUES ('2', '钱程', '男', '2', '9', '2001.2.2', '江西南昌');
INSERT INTO `student` VALUES ('3', '孙三', '男', '3', '8', '2001.3.3', '黑龙江哈尔滨');
INSERT INTO `student` VALUES ('4', '李四', '男', '4', '7', '2001.4.14', '河北石家庄');
INSERT INTO `student` VALUES ('5', '周五', '男', '5', '6', '2001.5.4', '山西太原');
INSERT INTO `student` VALUES ('6', '吴太和', '女', '6', '5', '2001.6.1', '内蒙古呼和浩特');
INSERT INTO `student` VALUES ('7', '郑七', '男', '7', '4', '2001.7.1', '吉林长春');
INSERT INTO `student` VALUES ('8', '王力宏', '男', '1', '3', '2001.8.1', '江苏南京');
INSERT INTO `student` VALUES ('9', '冯绍峰', '男', '2', '2', '2001.9.10', '浙江杭州');
INSERT INTO `student` VALUES ('10', '陈芊芊', '女', '3', '1', '2001.10.1', '安徽合肥');
3、代码一共有三个java文件,都放在同一个叫做ZTY的包下。
4、代码部分:
DbProcess2.java
package ZTY;
import java.sql.*;
public class DbProcess2{
public Connection con = null;public Statement sta=null;
ResultSet rs = null;
static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
//注意!:下行3306后面的q1为我建立的数据库名,要改成自己建立的数据库名!!!
static final String DB_URL = "jdbc:mysql://localhost:3306/q2?useSSL=false&serverTimezone=UTC";
//数据库账号密码,也要改为自己的
static final String USER = "root";
static final String PASS = "2000918131X";
public DbProcess2(){
try {
//Mysql数据库设置驱动程序类型
Class.forName(JDBC_DRIVER);
System.out.println("连接数据库...");
System.out.println("mysql数据库驱动加载成功");
}
catch(java.lang.ClassNotFoundException e)
{
e.printStackTrace();
}
}
public void executeUpdate(String sql)
{
connect();
try{
sta=con.createStatement();
sta.execute(sql);
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
disconnect();
}
public void queryall(String sql)
{
connect();
String s1="select change_code.DSRPIN,chang.REC_TIME,chang.DSRPIN as REASON from chang join change_code on change_code.CODE = chang.CHAN";
s1=s1+" where STUDENTID = "+sql;
System.out.println(s1);
String s2="select reward_levels.DSRPIN,reward.REC_TIME,reward.DSRPIN as REASON from reward join reward_levels on reward_levels.CODE=reward.LEVELS";
s2=s2+" where STUDENTID = "+sql;
System.out.println(s2);
String s3="select punish_levels.DSRPIN,punishment.REC_TIME,punishment.DSRPIN as REASON,punishment.ENABLE from punishment join punish_levels on punish_levels.CODE=punishment.LEVELS";
s3=s3+" where STUDENTID = "+sql;
System.out.println(s3);
try{
sta=con.createStatement();
ResultSet RS1=sta.executeQuery(s1);
while(RS1.next())
{
String P1=RS1.getString("DSRPIN");
String P2=RS1.getString("REC_TIME");
String P3=RS1.getString("REASON");
System.out.println(P1);System.out.println(P2);System.out.println(P3);
}
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
disconnect();
}
public void connect()
{
try{
//mysql数据库
con = DriverManager.getConnection(DB_URL,USER,PASS);
if(con!=null){
System.out.println("数据库连接成功");
}
}
catch(Exception e){
e.printStackTrace();
}
}
public void disconnect(){
try{
if(con != null){
System.out.println("数据库断开成功");
con.close();
con = null;
}
}
catch(Exception e){
e.printStackTrace();
}
}
public ResultSet executeQuery(String sql) {
try {
System.out.println("executeQuery(). sql = " + sql);
PreparedStatement pstm = con.prepareStatement(sql);
// 执行查询
rs = pstm.executeQuery();
}
catch(SQLException ex) {
ex.printStackTrace();
}
return rs;
}
public int executeUpdate1(String sql) {
int count = 0;
connect();
try {
Statement stmt = con.createStatement();
count = stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
disconnect();
return count;
}
}
login.java
package ZTY;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class login implements ActionListener {
// 定义主窗口
private final JFrame jf;
// 定义输入用户名和密码的标签提示
private final JLabel InputUserName;
private final JLabel InputPassWord;
// 定义输入用户名文本框
private final JTextField UserName;
// 定义输入密码框
private final JPasswordField PassWord;
// 定义登录和取消按钮
private final JButton Login;
private final JButton Cancel;
login() {
// 各组件实例化过程
jf = new JFrame("学生信息管理系统");
InputUserName = new JLabel(" ID: ");
InputPassWord = new JLabel("password:");
UserName = new JTextField();
PassWord = new JPasswordField();
Login = new JButton("登录");
Cancel = new JButton("退出");
// 设置主窗口大小、位置和布局
jf.setSize(400, 150);
jf.setLocation(600, 400);
// 设置窗口流式布局
jf.setLayout(new FlowLayout());
// 设置用户名和密码框大小
UserName.setPreferredSize(new Dimension(300, 30));
PassWord.setPreferredSize(new Dimension(300, 30));
// 依次向主窗口添加各组件
jf.getContentPane().add(InputUserName);
jf.getContentPane().add(UserName);
jf.getContentPane().add(InputPassWord);
jf.getContentPane().add(PassWord);
jf.getContentPane().add(Login);
jf.getContentPane().add(Cancel);
// 设置主窗口不可调节大小
jf.setResizable(false);
// 设置主窗口默认关闭操作
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 给登录和取消按钮添加 Action 监听器
Login.addActionListener(this);
Cancel.addActionListener(this);
// 设置主窗口可见
jf.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// 如果单击【退出】按钮则程序退出
if (e.getSource().equals(Cancel)) {
System.exit(0);
}
// 如果单击【登录】按钮则检查用户名和密码是否匹配
else if (e.getSource().equals(Login)) {
// 如果用户名和密码匹配,则打开具体操作面板
if (UserName.getText().equals("root") && String.valueOf(PassWord.getPassword()).equals("123")) {
jf.setVisible(false);
jf.dispose();
QUESTIONONE2 hh= new QUESTIONONE2();
}
// 如果用户名和密码不匹配,则给出提示对话框
else {
JOptionPane.showOptionDialog(jf, "用户名或密码错误", "登陆失败",
JOptionPane.CLOSED_OPTION,
JOptionPane.ERROR_MESSAGE, null, null, null);
}
}
}
// 启动登录界面
public static void main(String[] args) {
new login();
}
}
QUESTIONONE2.java
package ZTY;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
public class QUESTIONONE2 extends JFrame{
JPanel jap =null;
JPanel jap1=null;
JTextField JaTF1=null;JLabel jab1 = null;
JPanel jap2=null;
JTextField JaTF2=null;JLabel jab2 = null;
JPanel jap3=null;
JTextField JaTF3=null;JLabel jab3 = null;
JPanel jap4=null;
JTextField JaTF4=null;JLabel jab4 = null;
JPanel jap5=null;
JTextField JaTF5=null;JLabel jab5 = null;
JPanel jap6=null;
JTextField JaTF6=null;JLabel jab6 = null;
JPanel jap7=null;
JTextField JaTF7=null;JLabel jab7 =null;
JPanel jap8=null;
JButton jab=null;
JPanel jap9=null;JLabel jab9=null;
JPanel jbp =null;
JPanel jbp1=null;JTextField JbTF1=null;JLabel jbb1 = null;
JPanel jbp2=null;JTextField JbTF2=null;JLabel jbb2 = null;
JPanel jbp3=null;JTextField JbTF3=null;JLabel jbb3 = null;
JPanel jbp4=null;JTextField JbTF4=null;JLabel jbb4 = null;
JPanel jbp5=null;JTextField JbTF5=null;JLabel jbb5 = null;
JButton jbb=null;
JPanel jcp =null;
JPanel jcp1=null;JTextField JcTF1=null;JLabel jcb1 = null;
JPanel jcp2=null;JTextField JcTF2=null;JLabel jcb2 = null;
JPanel jcp3=null;JTextField JcTF3=null;JLabel jcb3 = null;
JPanel jcp4=null;JTextField JcTF4=null;JLabel jcb4 = null;
JPanel jcp5=null;JTextField JcTF5=null;JLabel jcb5 = null;
JButton jcb=null;
JPanel jdp =null;
JPanel jdp1=null;JTextField JdTF1=null;JLabel jdb1 = null;
JPanel jdp2=null;JTextField JdTF2=null;JLabel jdb2 = null;
JPanel jdp3=null;JTextField JdTF3=null;JLabel jdb3 = null;
JPanel jdp4=null;JTextField JdTF4=null;JLabel jdb4 = null;
JPanel jdp5=null;JTextField JdTF5=null;JLabel jdb5 = null;
JPanel jdp6=null;JTextField JdTF6=null;JLabel jdb6 = null;
JButton jdb=null;
JPanel jep =null;
JPanel jep1=null;JTextField JeTF1=null;JLabel jeb1 = null;
JPanel jep2=null;JButton JeB1=null;
JPanel jep3=null;JButton JeB2=null;
JPanel jep4=null;JTextField JeTF4=null;JLabel jeb4 = null;
JPanel jep5=null;JTextField JeTF5=null;JLabel jeb5 = null;
JPanel jep6=null;JTextField JeTF6=null;JLabel jeb6 = null;
JPanel jep7=null;JTextField JeTF7=null;JLabel jeb7 = null;
JPanel jep8=null;JTextField JeTF8=null;JLabel jeb8 = null;
JPanel jep9=null;JTextField JeTF9=null;JLabel jeb9 = null;
JPanel jep10=null;JTextField JeTF10=null;JLabel jeb10 = null;
JPanel jep11=null;JTextField JeTF11=null;JLabel jeb11 = null;
JPanel jep12=null;JTextField JeTF12=null;JLabel jeb12 = null;
JPanel jep13=null;JTextField JeTF13=null;JLabel jeb13 = null;
JTabbedPane JTP =null;
JTable studentJTable = null;
JScrollPane studentJScrollPane = null;
Vector studentVector = null;
Vector titleVector = null;
JButton jBQueryAll = null;
JButton jBDeleteCurrentRecord = null;
JButton jBDeleteAllRecords = null;
private static DbProcess2 dbProcess=new DbProcess2();
String SelectQueryFieldStr="";
public QUESTIONONE2 (){
JComboBox<String>jCBSelectQueryField = new JComboBox<String>();//查询字段
jCBSelectQueryField.addItem("学号");
jCBSelectQueryField.addItem("姓名");
jCBSelectQueryField.addItem("性别");
jCBSelectQueryField.addItem("班级");
jCBSelectQueryField.addItem("院系");
jCBSelectQueryField.addItem("生日");
jCBSelectQueryField.addItem("住址");
jCBSelectQueryField.addItemListener(new ItemListener() {//下拉框事件监听
public void itemStateChanged(ItemEvent event) {
switch (event.getStateChange()) {
case ItemEvent.SELECTED:
SelectQueryFieldStr = (String) event.getItem();
System.out.println("选中:" + SelectQueryFieldStr);
break;
case ItemEvent.DESELECTED:
System.out.println("取消选中:" + event.getItem());
break;
}
}
});
jap=new JPanel(new GridLayout(9,1));//return jap;
jap1=new JPanel();
JaTF1=new JTextField(8);
jab1 = new JLabel("学号");
jab1.setFont(new Font(null,Font.PLAIN,20));
jap1.add(jab1);
jap1.add(JaTF1);
jap2=new JPanel();
JaTF2=new JTextField(8);
jab2 = new JLabel("姓名");
jab2.setFont(new Font(null,Font.PLAIN,20));
jap2.add(jab2);
jap2.add(JaTF2);
jap3=new JPanel();
JaTF3=new JTextField(8);
jab3 = new JLabel("性别");
jab3.setFont(new Font(null,Font.PLAIN,20));
jap3.add(jab3);
jap3.add(JaTF3);
JComboBox<String> jCBSexField = new JComboBox<String>();
jCBSexField.addItem("男");
jCBSexField.addItem("女");
jCBSexField.addItemListener(new ItemListener() {//下拉框事件监听
public void itemStateChanged(ItemEvent event) {
String SexFieldStr;
switch (event.getStateChange()) {
case ItemEvent.SELECTED:
SexFieldStr = (String) event.getItem();
System.out.println("选中:" + SexFieldStr);
JaTF3.setText(jCBSexField.getSelectedItem().toString());
break;
case ItemEvent.DESELECTED:
System.out.println("取消选中:" + event.getItem());
break;
}
}
});
jap3.add(jCBSexField);
jap4=new JPanel();
JaTF4=new JTextField(8);
jab4 = new JLabel("生日");
jab4.setFont(new Font(null,Font.PLAIN,20));
jap4.add(jab4);
jap4.add(JaTF4);
jap5=new JPanel();
JaTF5=new JTextField(8);
jab5 = new JLabel("籍贯");
jab5.setFont(new Font(null,Font.PLAIN,20));
jap5.add(jab5);
jap5.add(JaTF5);
jap6=new JPanel();
JaTF6=new JTextField(8);
jab6 = new JLabel("院系");
jab6.setFont(new Font(null,Font.PLAIN,20));
jap6.add(jab6);
jap6.add(JaTF6);
jap7=new JPanel();
JaTF7=new JTextField(8);
jab7 = new JLabel("班级");
jab7.setFont(new Font(null,Font.PLAIN,20));
jap7.add(jab7);
jap7.add(JaTF7);
jap8=new JPanel();
jab=new JButton("输入");
jab.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("输入")
&&!JaTF1.getText().isEmpty()
&&!JaTF2.getText().isEmpty()
&&!JaTF3.getText().isEmpty()
&&!JaTF4.getText().isEmpty()
&&!JaTF5.getText().isEmpty()
&&!JaTF6.getText().isEmpty()
&&!JaTF7.getText().isEmpty())
{
System.out.println("actionPerformed(). 输入");
String sNo=JaTF1.getText().trim();
String sName=JaTF2.getText().trim();
String sSex=JaTF3.getText().trim();
String sBir=JaTF4.getText().trim();
String sHom=JaTF5.getText().trim();
String sDep=JaTF6.getText().trim();
String sCla=JaTF7.getText().trim();
String sql = "insert into student(STUDENTID,NAME,SEX,CLASS,DEPARTMENT,BIRTHDAY,NATIVE_PLACE) values(";
sql = sql + sNo + ",'"+ sName + "','" + sSex + "'," + sCla + "," + sDep + ",'" + sBir + "','" + sHom + "')";
System.out.println(sql);
new DbProcess2().executeUpdate(sql);
}
}
});
jBQueryAll = new JButton("查询所有记录");
jBDeleteCurrentRecord = new JButton("删除当前记录");
jBDeleteAllRecords = new JButton("删除所有记录");
studentVector = new Vector();
titleVector = new Vector();
// 定义表头
titleVector.add("学号");
titleVector.add("姓名");
titleVector.add("性别");
titleVector.add("班级");
titleVector.add("院系");
titleVector.add("生日");
titleVector.add("住址");
//studentTableModel = new DefaultTableModel(tableTitle, 15);
studentJTable = new JTable(studentVector, titleVector);
studentJTable.setPreferredScrollableViewportSize(new Dimension(500,160));
studentJScrollPane = new JScrollPane(studentJTable);
//分别设置水平和垂直滚动条自动出现
studentJScrollPane.setHorizontalScrollBarPolicy(
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
studentJScrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
jBQueryAll.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
System.out.println("actionPerformed(). 查询所有记录");
queryAllProcess();
}
});
jBDeleteCurrentRecord.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
System.out.println("actionPerformed(). 删除当前记录");
deleteCurrentRecordProcess();
}
});
jBDeleteAllRecords.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
System.out.println("actionPerformed(). 删除所有记录");
deleteAllRecordsProcess();
}
});
Dimension preferredSize = new Dimension(150,20);
jab.setPreferredSize(preferredSize);
jap8.add(jab);
jab9=new JLabel("<html>作者:pumpkin</html>");
jap9=new JPanel(new FlowLayout());//布局
jap9.add(jab9);
jap.add(jap1);
jap.add(jap2);
jap.add(jap3);
jap.add(jap4);
jap.add(jap5);
jap.add(jap6);
jap.add(jap7);
jap.add(jap8);
jap.add(jap9);
jbp=new JPanel();//return jbp;
jbp1=new JPanel();
jbp2=new JPanel();
jbp3=new JPanel();
jbp4=new JPanel();
jbp5=new JPanel();
JbTF1=new JTextField(8);
jbb1=new JLabel("记录号");
jbb1.setFont(new Font(null,Font.PLAIN,20));
jbp1.add(jbb1);jbp1.add(JbTF1);
JbTF2=new JTextField(8);
jbb2=new JLabel("学号");
jbb2.setFont(new Font(null,Font.PLAIN,20));
jbp2.add(jbb2);jbp2.add(JbTF2);
JTextField JbTF3=new JTextField(4);
JLabel jbb3=new JLabel("变更代码");
jbb3.setFont(new Font(null,Font.PLAIN,20));
jbp3.add(jbb3);jbp3.add(JbTF3);
JbTF4=new JTextField(6);
jbb4=new JLabel("记录时间");
jbb4.setFont(new Font(null,Font.PLAIN,20));
jbp4.add(jbb4);jbp4.add(JbTF4);
JbTF5=new JTextField(11);
jbb5=new JLabel("描述");
jbb5.setFont(new Font(null,Font.PLAIN,20));
jbp5.add(jbb5);jbp5.add(JbTF5);
jbb=new JButton("输入");
Dimension preferredSize2 = new Dimension(136,20);
jbb.setPreferredSize(preferredSize2);
jbp5.add(jbb);
jbp.add(jbp1);jbp.add(jbp2);jbp.add(jbp3);jbp.add(jbp4);jbp.add(jbp5);
jbb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("输入")
&&!JbTF1.getText().isEmpty()
&&!JbTF2.getText().isEmpty()
&&!JbTF3.getText().isEmpty()
&&!JbTF4.getText().isEmpty()
&&!JbTF5.getText().isEmpty())
{
System.out.println("actionPerformed(). 输入");
String ID=JbTF1.getText().trim();
String SI=JbTF2.getText().trim();
String CE=JbTF3.getText().trim();
String R_T=JbTF4.getText().trim();
String DSRPIN=JbTF5.getText().trim();
String sql = "insert into chang(ID,STUDENTID,CHAN,REC_TIME,DSRPIN) values(";
sql=sql +ID+','+SI+','+CE+','+"'"+R_T+"'"+ ','+"'"+DSRPIN+"')";
System.out.println(sql);
new DbProcess2().executeUpdate(sql);
}
}
});
jcp=new JPanel();//return jcp;
jcp1=new JPanel();
jcp2=new JPanel();
jcp3=new JPanel();
jcp4=new JPanel();
jcp5=new JPanel();
JcTF1=new JTextField(8);
jcb1=new JLabel("记录号");
jcb1.setFont(new Font(null,Font.PLAIN,20));
jcp1.add(jcb1);jcp1.add(JcTF1);
JcTF2=new JTextField(8);
jcb2=new JLabel("学号");
jcb2.setFont(new Font(null,Font.PLAIN,20));
jcp2.add(jcb2);jcp2.add(JcTF2);
JcTF3=new JTextField(4);
jcb3=new JLabel("级别代码");
jcb3.setFont(new Font(null,Font.PLAIN,20));
jcp3.add(jcb3);jcp3.add(JcTF3);
JcTF4=new JTextField(6);
jcb4=new JLabel("记录时间");
jcb4.setFont(new Font(null,Font.PLAIN,20));
jcp4.add(jcb4);jcp4.add(JcTF4);
JcTF5=new JTextField(11);
jcb5=new JLabel("描述");
jcb5.setFont(new Font(null,Font.PLAIN,20));
jcp5.add(jcb5);jcp5.add(JcTF5);
jcb=new JButton("输入");
Dimension preferredSize3 = new Dimension(136,20);
jcb.setPreferredSize(preferredSize3);
jcp5.add(jcb);
jcp.add(jcp1);jcp.add(jcp2);jcp.add(jcp3);jcp.add(jcp4);jcp.add(jcp5);
jcb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("输入")
&&!JcTF1.getText().isEmpty()
&&!JcTF2.getText().isEmpty()
&&!JcTF3.getText().isEmpty()
&&!JcTF4.getText().isEmpty()
&&!JcTF5.getText().isEmpty())
{
System.out.println("actionPerformed(). 输入");
String ID=JcTF1.getText().trim();
String SI=JcTF2.getText().trim();
String LEVELS=JcTF3.getText().trim();
String R_T=JcTF4.getText().trim();
String DSRPIN=JcTF5.getText().trim();
String sql = "insert into reward(ID,STUDENTID,LEVELS,REC_TIME,DSRPIN) values(";
sql=sql +ID+','+SI+','+LEVELS+','+"'"+R_T+"'"+ ','+"'"+DSRPIN+"')";
System.out.println(sql);
new DbProcess2().executeUpdate(sql);
}
}
});
jdp=new JPanel();// return jdp;
jdp1=new JPanel();
jdp2=new JPanel();
jdp3=new JPanel();
jdp4=new JPanel();
jdp5=new JPanel();
jdp6=new JPanel();
JdTF1=new JTextField(8);
jdb1=new JLabel("记录号");
jdb1.setFont(new Font(null,Font.PLAIN,20));
jdp1.add(jdb1);jdp1.add(JdTF1);
JdTF2=new JTextField(8);
jdb2=new JLabel("学号");
jdb2.setFont(new Font(null,Font.PLAIN,20));
jdp2.add(jdb2);jdp2.add(JdTF2);
JdTF3=new JTextField(5);
jdb3=new JLabel("级别代码");
jdb3.setFont(new Font(null,Font.PLAIN,20));
jdp3.add(jdb3);jdp3.add(JdTF3);
JdTF4=new JTextField(6);
jdb4=new JLabel("记录时间");
jdb4.setFont(new Font(null,Font.PLAIN,20));
jdp4.add(jdb4);jdp4.add(JdTF4);
JdTF5=new JTextField(10);
jdb5=new JLabel("描述");
jdb5.setFont(new Font(null,Font.PLAIN,20));
jdp5.add(jdb5);jdp5.add(JdTF5);
JdTF6=new JTextField(4);
jdb6=new JLabel("是否生效");
jdb6.setFont(new Font(null,Font.PLAIN,20));
jdp6.add(jdb6);jdp6.add(JdTF6);
jdb=new JButton("输入");
Dimension preferredSize4 = new Dimension(136,20);
jdb.setPreferredSize(preferredSize4);
jdp.add(jdp1);jdp.add(jdp2);jdp.add(jdp3);jdp.add(jdp4);jdp.add(jdp5);jdp.add(jdp6);jdp.add(jdb);
jdb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("输入")
&&!JdTF1.getText().isEmpty()
&&!JdTF2.getText().isEmpty()
&&!JdTF3.getText().isEmpty()
&&!JdTF4.getText().isEmpty()
&&!JdTF5.getText().isEmpty()
&&!JdTF6.getText().isEmpty())
{
System.out.println("actionPerformed(). 输入");
String ID=JdTF1.getText().trim();
String SI=JdTF2.getText().trim();
String LEVELS=JdTF3.getText().trim();
String R_T=JdTF4.getText().trim();
String DSRPIN=JdTF5.getText().trim();
String ENABLE=JdTF6.getText().trim();
String sql = "insert into punishment(ID,STUDENTID,LEVELS,REC_TIME,ENABLE,DSRPIN) values(";
sql=sql +ID+','+SI+','+LEVELS+','+"'"+R_T+"'"+ ','+ "'" + ENABLE + "',"+"'"+DSRPIN+"')";
System.out.println(sql);
new DbProcess2().executeUpdate(sql);
}//输入级别为0-4之间不能超过4
}
});
jep=new JPanel();// return jep;
jep1=new JPanel();
jep2=new JPanel();
jep3=new JPanel();
jep4=new JPanel();
jep5=new JPanel();
jep6=new JPanel();
jep7=new JPanel();
jep8=new JPanel();
jep9=new JPanel();
jep10=new JPanel();
jep11=new JPanel();
jep12=new JPanel();
jep13=new JPanel();
JeTF1=new JTextField(8);
jeb1=new JLabel("");
jeb1.setFont(new Font(null,Font.PLAIN,20));
jep1.add(jeb1);
jep1.add(jCBSelectQueryField);
jep1.add(JeTF1);
JeB1=new JButton("查询");
Dimension preferredSize5 = new Dimension(136,20);
JeB1.setPreferredSize(preferredSize5);
JeB1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("查询")&&!JeTF1.getText().trim().isEmpty())
{
String sql=JeTF1.getText().trim();
queryall(sql);
queryProcess(sql);
}
}
});
jep2.add(JeB1);
JeB2=new JButton("修改");
jep3.add(JeB2);
JeTF4=new JTextField(8);
jeb4=new JLabel("学籍变动");
jeb4.setFont(new Font(null,Font.PLAIN,20));
jep4.add(jeb4);jep4.add(JeTF4);
JeTF5=new JTextField(8);
jeb5=new JLabel("记录时间");
jeb5.setFont(new Font(null,Font.PLAIN,20));
jep5.add(jeb5);jep5.add(JeTF5);
JeTF6=new JTextField(8);
jeb6=new JLabel("描述");
jeb6.setFont(new Font(null,Font.PLAIN,20));
jep6.add(jeb6);jep6.add(JeTF6);
JeTF7=new JTextField(8);
jeb7=new JLabel("奖励");
jeb7.setFont(new Font(null,Font.PLAIN,20));
jep7.add(jeb7);jep7.add(JeTF7);
JeTF8=new JTextField(8);
jeb8=new JLabel("记录时间");
jeb8.setFont(new Font(null,Font.PLAIN,20));
jep8.add(jeb8);jep8.add(JeTF8);
JeTF9=new JTextField(8);
jeb9=new JLabel("描述");
jeb9.setFont(new Font(null,Font.PLAIN,20));
jep9.add(jeb9);jep9.add(JeTF9);
JeTF10=new JTextField(4);
jeb10=new JLabel("处罚");
jeb10.setFont(new Font(null,Font.PLAIN,20));
jep10.add(jeb10);jep10.add(JeTF10);
JeTF11=new JTextField(3);
jeb11=new JLabel("记录时间");
jeb11.setFont(new Font(null,Font.PLAIN,20));
jep11.add(jeb11);jep11.add(JeTF11);
JeTF12=new JTextField(8);
jeb12=new JLabel("描述");
jeb12.setFont(new Font(null,Font.PLAIN,20));
jep12.add(jeb12);jep12.add(JeTF12);
JeTF13=new JTextField(2);
jeb13=new JLabel("是否生效");
jeb13.setFont(new Font(null,Font.PLAIN,20));
jep13.add(jeb13);jep13.add(JeTF13);
Dimension preferredSize6 = new Dimension(136,20);
JeB2.setPreferredSize(preferredSize6);
JeB2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("修改")&&!JeTF1.getText().trim().isEmpty())
{
String sql=JeTF1.getText().trim();
changeall(sql);
queryall(sql);
}
}
});
jep.add(jep1);jep.add(jep2);jep.add(jep3);
jep.add(jep4);jep.add(jep5);jep.add(jep6);
jep.add(jep7);jep.add(jep8);jep.add(jep9);
jep.add(jep10);jep.add(jep11);jep.add(jep12);jep.add(jep13);
jep.add(studentJScrollPane);//
jep.add(jBQueryAll);
jep.add(jBDeleteCurrentRecord);
jep.add(jBDeleteAllRecords);
JTP=new JTabbedPane();
JTP.addTab("学生个人情况查询和修改界面",jep);
JTP.addTab("学生个人信息输入界面 ",jap);
JTP.addTab("学籍变更情况输入界面",jbp);
JTP.addTab("奖励信息输入界面",jcp);
JTP.addTab("处罚情况输入界面",jdp);
JTP.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
System.out.println("当前选中的选项卡: " + JTP.getSelectedIndex());
}
});
// 设置默认选中的选项卡
JTP.setSelectedIndex(0);
this.add(JTP);
this.setLayout(new GridLayout(2, 1));
this.setContentPane(JTP);
this.setSize(600,500);
this.setLocation(400, 180);
this.setTitle("学生信息管理系统");
this.setBackground(Color.blue);
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[]){
// TODO Auto-generated method stub
QUESTIONONE2 hh= new QUESTIONONE2();
}
public void queryall(String sql)
{
String s1="select change_code.DSRPIN,chang.REC_TIME,chang.DSRPIN as REASON from chang join change_code on change_code.CODE = chang.CHAN";
s1=s1+" where "+jCBSelectQueryFieldTransfer(SelectQueryFieldStr)+" = "+sql;
String s2="select reward_levels.DSRPIN,reward.REC_TIME,reward.DSRPIN as REASON from reward join reward_levels on reward_levels.CODE=reward.LEVELS";
s2=s2+" where "+jCBSelectQueryFieldTransfer(SelectQueryFieldStr)+" = "+sql;
String s3="select punish_levels.DSRPIN,punishment.REC_TIME,punishment.DSRPIN as REASON,punishment.ENABLE from punishment join punish_levels on punish_levels.CODE=punishment.LEVELS";
s3=s3+" where "+jCBSelectQueryFieldTransfer(SelectQueryFieldStr)+" = "+sql;
try{
dbProcess.connect();
dbProcess.sta=dbProcess.con.createStatement();
ResultSet RS1=dbProcess.sta.executeQuery(s1);
while(RS1.next())
{
String P1=RS1.getString("DSRPIN");
String P2=RS1.getString("REC_TIME");
String P3=RS1.getString("REASON");
System.out.println(P1);System.out.println(P2);System.out.println(P3);
JeTF4.setText(P1);JeTF5.setText(P2);JeTF6.setText(P3);
}
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
dbProcess.disconnect();
try {
dbProcess.connect();
dbProcess.sta=dbProcess.con.createStatement();
ResultSet RS1=dbProcess.sta.executeQuery(s2);
while(RS1.next())
{
String P4=RS1.getString("DSRPIN");
String P5=RS1.getString("REC_TIME");
String P6=RS1.getString("REASON");
System.out.println(P4);System.out.println(P5);System.out.println(P6);
JeTF7.setText(P4);JeTF8.setText(P5);JeTF9.setText(P6);
}
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
dbProcess.disconnect();
try {
dbProcess.connect();
dbProcess.sta=dbProcess.con.createStatement();
ResultSet RS1=dbProcess.sta.executeQuery(s3);
while(RS1.next())
{
String P7=RS1.getString("DSRPIN");
String P8=RS1.getString("REC_TIME");
String P9=RS1.getString("REASON");
String P10=RS1.getString("ENABLE");
System.out.println(P7);System.out.println(P8);System.out.println(P9);
JeTF10.setText(P7);JeTF11.setText(P8);JeTF12.setText(P9);JeTF13.setText(P10);
}
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
dbProcess.disconnect();
}
public void queryProcess(String sQueryField)
{
try{
// 建立查询条件
String sql = "select * from student where ";
String queryFieldStr = jCBSelectQueryFieldTransfer(SelectQueryFieldStr);
if(queryFieldStr.equals("STUDENTID")||queryFieldStr.equals("CLASS")||queryFieldStr.equals("DEPARTMENT")){
sql = sql + queryFieldStr;
sql = sql + " = " + sQueryField;
}else{
sql = sql + queryFieldStr;
sql = sql + " = ";
sql = sql + "'" + sQueryField + "';";
}
System.out.println("queryProcess(). sql = " + sql);
dbProcess.connect();
ResultSet rs = dbProcess.executeQuery(sql);
// 将查询获得的记录数据,转换成适合生成JTable的数据形式
studentVector.clear();
while(rs.next()){
Vector v = new Vector();
v.add(Integer.valueOf(rs.getInt("STUDENTID")));
v.add(rs.getString("NAME"));
v.add(rs.getString("SEX"));
v.add(Integer.valueOf(rs.getInt("CLASS")));
v.add(Integer.valueOf(rs.getInt("DEPARTMENT")));
v.add(rs.getString("BIRTHDAY"));
v.add(rs.getString("NATIVE_PLACE"));
studentVector.add(v);
}
studentJTable.updateUI();
dbProcess.disconnect();
}catch(SQLException sqle){
System.out.println("sqle = " + sqle);
JOptionPane.showMessageDialog(null,
"数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
}catch(Exception e){
System.out.println("e = " + e);
JOptionPane.showMessageDialog(null,
"数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
}
}
public void changeall(String sql)
{
String changchan=JeTF4.getText();
String changtime=JeTF5.getText();
String changedes=JeTF6.getText();
String rew=JeTF7.getText();
String rewtime=JeTF8.getText();
String rewdesc=JeTF9.getText();
String pun=JeTF10.getText();
String puntime=JeTF11.getText();
String pundesc=JeTF12.getText();
String punfun=JeTF13.getText();
String d1="update chang set CHAN=(select a.CHAN from (select CHAN,CODE from chang,change_code where chang.CHAN=change_code.CODE AND chang_code.DSRPIN ="+changchan+" group by CHAN)as a),"
+"REC_TIME ='"+changtime+"',"+"DSRPIN ='"+changedes+"' "
+"where STUDENTID"+" = "+sql;
System.out.println(d1);
String d2="update reward set LEVELS=(select b.LEVELS from (select LEVELS,CODE from reward,reward_levels where reward.LEVELS=reward_levels.CODE AND reward_levels.DSRPIN ='"+rew+"' group by LEVELS)as b),"
+"REC_TIME ='"+rewtime+"' ,"+"DSRPIN ='"+rewdesc+"' "
+"where STUDENTID"+" = "+sql;
System.out.println(d2);
String d3="update punishment set LEVELS=(select c.LEVELS from(select LEVELS,CODE from punishment,punish_levels where punishment.LEVELS=punish_levels.CODE AND punish_levels.DSRPIN ='"+pun+"' group by LEVELS)as c),"
+"REC_TIME ='"+puntime+"',"+"DSRPIN ='"+pundesc+"' ,"+"ENABLE ='"+punfun+"' "
+"where STUDENTID"+" = "+sql;
System.out.println(d3);
try {
dbProcess.connect();
dbProcess.sta=dbProcess.con.createStatement();
dbProcess.sta.execute(d1);
JeTF4.setText("");JeTF5.setText("");JeTF6.setText("");
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
dbProcess.disconnect();
try {
dbProcess.connect();
dbProcess.sta=dbProcess.con.createStatement();
dbProcess.sta.execute(d2);
JeTF7.setText("");JeTF8.setText("");JeTF9.setText("");
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
dbProcess.disconnect();
try {
dbProcess.connect();
dbProcess.sta=dbProcess.con.createStatement();
dbProcess.sta.execute(d3);
JeTF10.setText("");JeTF11.setText("");JeTF12.setText("");JeTF13.setText("");
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
dbProcess.disconnect();
}
public void queryAllProcess()
{
try{
// 建立查询条件
String sql = "select * from student;";
System.out.println("queryAllProcess(). sql = " + sql);
dbProcess.connect();
ResultSet rs = dbProcess.executeQuery(sql);
// 将查询获得的记录数据,转换成适合生成JTable的数据形式
studentVector.clear();
while(rs.next()){
Vector v = new Vector();
v.add(Integer.valueOf(rs.getInt("STUDENTID")));
v.add(rs.getString("NAME"));
v.add(rs.getString("SEX"));
v.add(Integer.valueOf(rs.getInt("CLASS")));
v.add(Integer.valueOf(rs.getInt("DEPARTMENT")));
v.add(rs.getString("BIRTHDAY"));
v.add(rs.getString("NATIVE_PLACE"));
studentVector.add(v);
}
studentJTable.updateUI();
dbProcess.disconnect();
}catch(SQLException sqle){
System.out.println("sqle = " + sqle);
JOptionPane.showMessageDialog(null,
"数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
}
}
public void deleteCurrentRecordProcess()
{
String sNo = JeTF1.getText().trim();
// 建立删除条件
String sql = "delete from student where "+jCBSelectQueryFieldTransfer(SelectQueryFieldStr)+"='" + sNo + "';";
System.out.println("deleteCurrentRecordProcess(). sql = " + sql);
try{
if (dbProcess.executeUpdate1(sql) < 1) {
System.out.println("deleteCurrentRecordProcess(). delete database failed.");
}
}catch(Exception e){
System.out.println("e = " + e);
JOptionPane.showMessageDialog(null,
"数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
}
queryAllProcess();
}
public void deleteAllRecordsProcess()
{
// 建立删除条件
String sql = "delete from student;";
System.out.println("deleteAllRecordsProcess(). sql = " + sql);
try{
if (dbProcess.executeUpdate1(sql) < 1) {
System.out.println("deleteAllRecordsProcess(). delete database failed.");
}
}catch(Exception e){
System.out.println("e = " + e);
JOptionPane.showMessageDialog(null,
"数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
}
queryAllProcess();
}
public String jCBSelectQueryFieldTransfer(String InputStr)
{
String outputStr = "";
System.out.println("jCBSelectQueryFieldTransfer(). InputStr = " + InputStr);
if(InputStr.equals("学号")){
outputStr = "STUDENTID";
}else if(InputStr.equals("姓名")){
outputStr = "NAME";
}else if(InputStr.equals("性别")){
outputStr = "SEX";
}else if(InputStr.equals("班级")){
outputStr = "CLASS";
}else if(InputStr.equals("院系")){
outputStr = "DEPARTMENT";
}else if(InputStr.equals("生日")){
outputStr = "BIRTHDAY";
}else if(InputStr.equals("住址")){
outputStr = "NATIVE_PLACE";
}
System.out.println("jCBSelectQueryFieldTransfer(). outputStr = " + outputStr);
return outputStr;
}
}
功能实现:登录输入ID:root,密码123后跳转到系统页面
PS: 需要注意的其他事项在https://blog.csdn.net/Zhongtongyi/article/details/105031058中有说明,如有问题可评论区留言。