一、选题设计思想
学生信息管理系统是典型的信息管理系统(MIS),其开发主要包括后台数据库的建立和维护以及前端应用程序的开发。对于前者要求建立起数据一致性和完整性强、安全性高的数据库;对于后者则要求应用程序具有功能完备、易使用、易维护等特点。本文着重阐述了学生学籍管理系统的整体开发过程。介绍了系统的开发环境以及开发工具,对于设计思想和设计流程也做出了全面的叙述,在数据库创建思想以及各个数据表之间的具体关联等方面也做出了详细说明,并且具体剖析了系统各个功能的实现过程以及详细设计过程,在绘制简单系统功能模块图的同时,力求更加清晰地表明设计思想以及对整个程序设计的规划及具体实现。
二、环境
(1)WINDOWS 10操作系统
(2)eclipse、 Mysql、 navicat 、java_jdk1.8.0_201
三、软件截图
登录界面
学生登录
添加记录
更新记录
管理员登录
账号:admin 密码:1234
添加记录
删除记录
更新记录
信息查询
账号管理与信息查询
四、部分源代码
登录部分源代码
package project;import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;public class Login implements ActionListener {// 定义主窗口private final JFrame jf;// 定义输入用户名和密码的标签提示private final JLabel InputUserName;private final JLabel InputPassWord;private final JLabel Welcome;// 定义输入用户名文本框private final JTextField UserName;// 定义输入密码框private final JPasswordField PassWord;// 定义登录和取消按钮private final JButton LoginAdmin;private final JButton LoginStudent;private final JButton Register;private final JButton Cancel;Login() {// 各组件实例化过程jf = new JFrame("Login");InputUserName = new JLabel(" ID: ");InputPassWord = new JLabel("password:");Welcome = new JLabel("欢迎使用学生信息管理系统");Welcome.setFont(new Font("楷体", 1, 30));UserName = new JTextField();PassWord = new JPasswordField();LoginStudent= new JButton("学生登录");LoginAdmin=new JButton("管理员登录");Register =new JButton("学生注册");Cancel = new JButton("退出");// 设置主窗口大小、位置和布局jf.setSize(400, 200);jf.setLocation(600, 400);// 设置窗口流式布局jf.setLayout(new FlowLayout());// 设置用户名和密码框大小UserName.setPreferredSize(new Dimension(300, 30));PassWord.setPreferredSize(new Dimension(300, 30));// 依次向主窗口添加各组件jf.getContentPane().add(Welcome);jf.getContentPane().add(InputUserName);jf.getContentPane().add(UserName);jf.getContentPane().add(InputPassWord);jf.getContentPane().add(PassWord);jf.getContentPane().add(LoginStudent);jf.getContentPane().add(LoginAdmin);jf.getContentPane().add(Register);jf.getContentPane().add(Cancel);// 设置主窗口不可调节大小jf.setResizable(false);// 设置主窗口默认关闭操作jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 给登录和取消按钮添加 Action 监听器LoginStudent.addActionListener(this);LoginAdmin.addActionListener(this);Register.addActionListener(this);Cancel.addActionListener(this);// 设置主窗口可见jf.setVisible(true);}@Overridepublic void actionPerformed(ActionEvent e) {// 如果单击【退出】按钮则程序退出if (e.getSource().equals(Cancel)) {System.exit(0);}// 如果单击【学生登录】按钮则检查用户名和密码是否匹配else if (e.getSource().equals(LoginStudent)) {// 如果用户名和密码匹配,则打开具体操作面板if (check(UserName.getText(), String.valueOf(PassWord.getPassword()))) {JOptionPane.showMessageDialog(null, "学生登录成功");MySQLGUI myS = new MySQLGUI();myS.initial();// 初始化 base按键增加监听器jf.setVisible(false);jf.dispose(); //dispose是 java.awt.Windows类的方法,它的作用是销毁程序中指定的图形界面资源,对数据资源不产生影响。 }// 如果用户名和密码不匹配,则给出提示对话框else {JOptionPane.showMessageDialog(null, "用户名或密码错误", "学生登录失败", JOptionPane.ERROR_MESSAGE);}} // 如果单击【注册】按钮else if (e.getSource().equals(Register)) {// 如果注册成功if(!(UserName.getText().equals(""))) {RegisterUser/*注册方法*/(UserName.getText(), String.valueOf(PassWord.getPassword()));//valueOf类型转化JOptionPane.showMessageDialog(null, "注册成功");}// 如果注册失败else {JOptionPane.showMessageDialog(null, "注册失败");}} // 如果单击【管理员登录】按钮则检查用户名和密码是否匹配else if (UserName.getText().equals("admin") && String.valueOf(PassWord.getPassword()).equals("1234")) {JOptionPane.showMessageDialog(null, "管理员登录成功");MySQLGUI myS = new MySQLGUI("admin");myS.initial();// 初始化 base按键增加监听器jf.setVisible(false);jf.dispose();//dispose是 java.awt.Windows类的方法,它的作用是销毁程序中指定的图形界面资源,对数据资源不产生影响。 }// 如果用户名和密码不匹配,则给出提示对话框else {JOptionPane.showMessageDialog(null,"用户名或密码错误", "管理员登录失败", JOptionPane.ERROR_MESSAGE);} }//账号密码匹配private boolean check(String ID, String passw) {// TODO Auto-generated method stubStatement pstmt = null;ResultSet prs = null;Connection pconn = null;boolean flag = false;try {//1.注册数据库的驱动Class.forName("com.mysql.jdbc.Driver");//2.通过DriveMannager获取数据库连接String url = "jdbc:mysql://localhost:3306/StudentInfo";String username1 = "root";String password1 = "";pconn = DriverManager.getConnection(url, username1, password1);//3.通过Connection对象获取Statement对象pstmt = pconn.createStatement();//4.使用Statement执行SQL语句String sql = "select*from user";prs = pstmt.executeQuery(sql);while (prs.next()) {String id = prs.getString("id");//通过列名获取指定字段的值String psw = prs.getString("password");if (ID.equals(id)) {if (passw.equals(psw)) {flag = true;}}}} catch (Exception e) {e.printStackTrace();} finally {//6.回收数据库资源if (prs != null) {try {prs.close();} catch (SQLException e) {e.printStackTrace();}prs = null;}if (pstmt != null) {try {pstmt.close();} catch (SQLException e) {e.printStackTrace();}pstmt = null;}if (pconn != null) {try {pconn.close();} catch (SQLException e) {e.printStackTrace();}pconn = null;}}return flag;}//注册 增private boolean RegisterUser(String RegisterID,String RegisterPassword) {PreparedStatement qstmt = null;ResultSet qrs = null;Connection qconn = null;boolean flag=false;try {//1.注册数据库的驱动Class.forName("com.mysql.jdbc.Driver");//2.通过DriveMannager获取数据库连接String url = "jdbc:mysql://localhost:3306/StudentInfo";String username = "root";String password = "";qconn = DriverManager.getConnection(url, username, password);String sql="INSERT INTO user(ID,Password)"+"VALUES(?,?)";//1.创建执行SQL语句的PreparedStatement对象qstmt=qconn.prepareStatement(sql);//2.为SQL语句中的参数赋值qstmt.setString(1,RegisterID);qstmt.setString(2,RegisterPassword);//3.执行SQLqstmt.executeUpdate();flag=true;} catch (Exception e) {e.printStackTrace();} finally {//6.回收数据库资源if (qrs != null) {try {qrs.close();} catch (SQLException e) {e.printStackTrace();}qrs = null;}if (qstmt != null) {try {qstmt.close();} catch (SQLException e) {e.printStackTrace();}qstmt = null;}if (qconn != null) {try {qconn.close();} catch (SQLException e) {e.printStackTrace();}qconn = null;}}return flag;}}
MySQLGUI源代码
package project;import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;public class MySQLGUI extends JFrame implements MouseListener, ItemListener {// 定义一个数据库操作的实例private OperationMysql db = null;// 定义滚动条private JScrollPane scroll = null;// 定义一个复选框用于选择更新的项目private JComboBox<String> UpdateItem = null;MySQLGUI(String admin) {//如果为管理员模式// 设置各按钮信息setButton();// 设置各标签信息setLabel();// 设置各文本框信息setTextField();// 设置各面板信息setPanel();// 设置布局信息setLayout();// 设置选项卡信息setBase();// 设置主窗口信息setThis();// 设置数据库信息setDB();}MySQLGUI() {//如果为学生模式// 设置各按钮信息setButton();// 设置各标签信息setLabel();// 设置各文本框信息setTextField();// 设置各面板信息setPanel();// 设置布局信息setLayout();// 设置选项卡信息setBase2();// 设置主窗口信息setThis();// 设置数据库信息setDB();}// 定义各按钮/** StudentDate, 添加个人信息按钮* StudentDateClear,重置个人信息按钮* DeleteStudentDate, 删除个人信息按钮* DeleteStudentDateClear ,重置删除个人信息* updateStudentDate, 更新个人信息按钮* updateStudentDateClear,重置更新个人信息* ShowStudentDate ,搜索/显示个人信息* */private JButton StudentDate, StudentDateClear,DeleteStudentDate, DeleteStudentDateClear,updateStudentDate, updateStudentDateClear,ShowStudentDate,showStudentMessage,showStudentUser;private void setButton() {// jp1 上的按钮//添加个人信息StudentDate = new JButton("添加");StudentDate.setFont(new Font("宋体", 1, 20)); // 1 代表加粗,20 代表字体大小StudentDate.setBackground(Color.CYAN);//蓝绿色StudentDate.setBounds(150, 400, 100, 45);StudentDate.setMargin(new Insets(0, 0, 0, 0)); // 设置按钮的边缘空白为四个方向全为0,也即让按钮中的文本与按钮边缘贴齐//重置StudentDateClear = new JButton("重置");StudentDateClear.setFont(new Font("宋体", 1, 20));StudentDateClear.setBackground(Color.CYAN);StudentDateClear.setBounds(300, 400, 100, 45);//x,y,长,宽StudentDateClear.setMargin(new Insets(0, 0, 0, 0));// 设置按钮的边缘空白为四个方向全为0,也即让按钮中的文本与按钮边缘贴齐// jp2 上的按钮//删除信息DeleteStudentDate = new JButton("删除信息");DeleteStudentDate.setFont(new Font("宋体", 1, 20));// 1 代表加粗,20 代表字体大小DeleteStudentDate.setBackground(Color.CYAN);DeleteStudentDate.setBounds(150, 350, 100, 45);DeleteStudentDate.setMargin(new Insets(0, 0, 0, 0));// 设置按钮的边缘空白为四个方向全为0,也即让按钮中的文本与按钮边缘贴齐//重置DeleteStudentDateClear = new JButton("重置");DeleteStudentDateClear.setFont(new Font("宋体", 1, 20));// 1 代表加粗,20 代表字体大小DeleteStudentDateClear.setBackground(Color.CYAN);DeleteStudentDateClear.setBounds(300, 350, 100, 45);DeleteStudentDateClear.setMargin(new Insets(0, 0, 0, 0));// 设置按钮的边缘空白为四个方向全为0,也即让按钮中的文本与按钮边缘贴齐// jp3 上的按钮//更新updateStudentDate = new JButton("更新");updateStudentDate.setFont(new Font("宋体", 1, 20));// 1 代表加粗,20 代表字体大小updateStudentDate.setBackground(Color.CYAN);updateStudentDate.setBounds(250, 400, 100, 45);// 设置按钮的边缘空白为四个方向全为0,也即让按钮中的文本与按钮边缘贴齐//重置updateStudentDateClear = new JButton("重置");updateStudentDateClear.setFont(new Font("宋体", 1, 20));// 1 代表加粗,20 代表字体大小updateStudentDateClear.setBackground(Color.CYAN);updateStudentDateClear.setBounds(400, 400, 100, 45);//x,y,长,宽// jp4 上的按钮// jp4 上的按钮(小圆圈)ID = new JRadioButton("学号");ID.setFont(new Font("宋体", 1, 15));ID.setMargin(new Insets(0, 0, 0, 0));ID.setBounds(30, 300, 55, 20); //X , Y ,WIDE ,HIGHEName = new JRadioButton("姓名");Name.setFont(new Font("宋体", 1, 15));Name.setMargin(new Insets(0, 0, 0, 0));Name.setBounds(30, 330, 55, 20); //X , Y ,WIDE ,HIGHEBorn = new JRadioButton("出生");Born.setFont(new Font("宋体", 1, 15));Born.setMargin(new Insets(0, 0, 0, 0));Born.setBounds(30, 360, 55, 20); //X , Y ,WIDE ,HIGHEClass = new JRadioButton("班级");Class.setFont(new Font("宋体", 1, 15));Class.setMargin(new Insets(0, 0, 0, 0));Class.setBounds(30, 390, 55, 20); //X , Y ,WIDE ,HIGHESex = new JRadioButton("性别");Sex.setFont(new Font("宋体", 1, 15));Sex.setMargin(new Insets(0, 0, 0, 0));Sex.setBounds(30, 420, 55, 20);AwardName = new JRadioButton("获奖名称");AwardName.setFont(new Font("宋体", 1, 15));AwardName.setMargin(new Insets(0, 0, 0, 0));AwardName.setBounds(290, 300, 100, 20); //X , Y ,WIDE ,HIGHEAwardLevel= new JRadioButton("获奖等级");AwardLevel.setFont(new Font("宋体", 1, 15));AwardLevel.setMargin(new Insets(0, 0, 0, 0));AwardLevel.setBounds(290, 330, 100, 20); //X , Y ,WIDE ,HIGHEAwardTime = new JRadioButton("获奖时间");AwardTime.setFont(new Font("宋体", 1,15));AwardTime.setMargin(new Insets(0, 0, 0, 0));AwardTime.setBounds(290, 360, 100, 20); //X , Y ,WIDE ,HIGHEAwardProject = new JRadioButton("获奖类别");AwardProject.setFont(new Font("宋体", 1, 15));AwardProject.setMargin(new Insets(0, 0, 0, 0));AwardProject.setBounds(290, 390, 100, 20); //X , Y ,WIDE ,HIGHEAwardTeam = new JRadioButton("获奖团名");AwardTeam .setFont(new Font("宋体", 1, 15));AwardTeam .setMargin(new Insets(0, 0, 0, 0));AwardTeam .setBounds(290, 420, 100, 20);ShowStudentDate = new JButton("查询");ShowStudentDate.setFont(new Font("宋体", 1, 20));ShowStudentDate.setBackground(Color.CYAN);ShowStudentDate.setBounds(600, 400, 80, 45); //X , Y ,WIDE ,HIGHE//jp5上的按钮showStudentMessage =new JButton("学生信息入情况总览");showStudentMessage.setFont(new Font("宋体", 1, 20));// 1 代表加粗,20 代表字体大小showStudentMessage.setBackground(Color.CYAN);showStudentMessage.setBounds(250, 400, 100, 45);showStudentUser =new JButton("学生账号注册情况总览");showStudentUser.setFont(new Font("宋体", 1, 20));// 1 代表加粗,20 代表字体大小showStudentUser.setBackground(Color.CYAN);showStudentUser.setBounds(250, 400, 100, 45);}// 定义各标签/** InsertID1, 插入学号提示标签* InsertName1, 插入姓名提示标签* InsertBorn1, 插入出生年月标签* InsertSex1, 插入性别标签* InsertClass1, 插入所在班级提示标签* InsertAwardName1, 插入获奖名称提示标签* InsertAwardLevel1, 插入获奖级别提示标签* InsertAwardTime1, 插入获奖时间提示标签* InsertAwardProject1, 插入获奖类别提示标签* InsertAwardTeam1, 插入获奖团队提示标签* */private JLabel InsertID1, InsertName1, InsertBorn1, InsertClass1,InsertSex1,DeleteID1,UpdateID1, InsertAwardName1, InsertAwardLevel1, InsertAwardTime1,InsertAwardTeam1,InsertAwardProject1;// 设置各标签信息的方法private void setLabel() {// jp1 上的标签InsertID1 = new JLabel("学 号:");InsertID1.setFont(new Font("楷体", 1, 22));InsertID1.setBackground(Color.GREEN);InsertID1.setBounds(100, 40, 120, 50);InsertName1 = new JLabel("姓 名:");InsertName1.setFont(new Font("楷体", 1, 22));InsertName1.setBackground(Color.GREEN);InsertName1.setBounds(100, 100, 120, 50);InsertBorn1 = new JLabel("出生年月:");InsertBorn1.setFont(new Font("楷体", 1, 22));InsertBorn1.setBackground(Color.GREEN);InsertBorn1.setBounds(100, 160, 120, 50);InsertClass1 = new JLabel("所属班级:");InsertClass1.setFont(new Font("楷体", 1, 22));InsertClass1.setBackground(Color.GREEN);InsertClass1.setBounds(100, 220, 120, 50);InsertSex1 = new JLabel("性 别:");InsertSex1.setFont(new Font("楷体", 1, 22));InsertSex1.setBackground(Color.GREEN);InsertSex1.setBounds(100, 280, 120, 50);InsertAwardName1 = new JLabel("获奖名称:");InsertAwardName1.setFont(new Font("楷体", 1, 22));InsertAwardName1.setBackground(Color.GREEN);InsertAwardName1.setBounds(450, 40, 120, 50);InsertAwardLevel1 = new JLabel("获奖等级:");InsertAwardLevel1.setFont(new Font("楷体", 1, 22));InsertAwardLevel1.setBackground(Color.GREEN);InsertAwardLevel1.setBounds(450, 100, 120, 50);InsertAwardTime1 = new JLabel("获奖时间:");InsertAwardTime1.setFont(new Font("楷体", 1, 22));InsertAwardTime1.setBackground(Color.GREEN);InsertAwardTime1.setBounds(450, 160, 120, 50);InsertAwardProject1 = new JLabel("获奖类别:");InsertAwardProject1.setFont(new Font("楷体", 1, 22));InsertAwardProject1.setBackground(Color.GREEN);InsertAwardProject1.setBounds(450, 220, 120, 50);InsertAwardTeam1 = new JLabel("获奖团名:");InsertAwardTeam1.setFont(new Font("楷体", 1, 22));InsertAwardTeam1.setBackground(Color.GREEN);InsertAwardTeam1.setBounds(450, 280, 120, 50);// jp2 上的标签DeleteID1 = new JLabel("学 号:");DeleteID1.setBounds(100, 100, 100, 50);DeleteID1.setFont(new Font("楷体", 1, 22));// jp3 上的标签UpdateID1 = new JLabel("学 号:");UpdateID1.setFont(new Font("楷体", 1, 22));UpdateID1.setBounds(200, 60, 120, 50);UpdateItem = new JComboBox<>();UpdateItem.setFont(new Font("楷体", 1, 22));UpdateItem.setBounds(150, 200, 150, 45);UpdateItem.addItem("姓名");UpdateItem.addItem("出生年月");UpdateItem.addItem("所属班级");UpdateItem.addItem("获奖名称");UpdateItem.addItem("获奖等级");UpdateItem.addItem("获奖时间");UpdateItem.addItem("获奖类别");UpdateItem.addItem("获奖团名");}// 设置布局信息的方法private void setLayout() {// 添加 jp1 的组件jp1.setLayout(null);jp1.add(StudentDate);jp1.add(StudentDateClear);jp1.add(InsertID1);jp1.add(InsertName1);jp1.add(InsertBorn1);jp1.add(InsertClass1);jp1.add(InsertSex1);jp1.add(InsertAwardName1);jp1.add(InsertAwardLevel1);jp1.add(InsertAwardTime1);jp1.add(InsertAwardTeam1);jp1.add(InsertAwardProject1);jp1.add(InsertID2);jp1.add(InsertName2);jp1.add(InsertBorn2);jp1.add(InsertClass2);jp1.add(InsertSex2);jp1.add(InsertAwardName2);jp1.add(InsertAwardLevel2);jp1.add(InsertAwardTime2);jp1.add(InsertAwardProject2);jp1.add(InsertAwardTeam2);// 添加 jp2 上的组件jp2.setLayout(null);jp2.add(DeleteID1);jp2.add(DeleteID2);jp2.add(DeleteStudentDate);jp2.add(DeleteStudentDateClear);// 添加 jp3 上的组件jp3.setLayout(null);jp3.add(UpdateID1);jp3.add(UpdateID2);jp3.add(UpdateItem);jp3.add(UpdateContent);jp3.add(updateStudentDate);jp3.add(updateStudentDateClear);// 添加 jp4 上的组件jp4.setLayout(null);jp4.add(scroll);//JScrollPanejp4.add(ID);jp4.add(Name);jp4.add(Born);jp4.add(Class);jp4.add(Sex);jp4.add(IDCondition);jp4.add(NameCondition);jp4.add(BornCondition);jp4.add(ClassCondition);jp4.add(SexCondition);jp4.add(AwardName);jp4.add(AwardLevel);jp4.add(AwardTime);jp4.add(AwardProject);jp4.add(AwardTeam);jp4.add(AwardNameCondition);jp4.add(AwardLevelCondition);jp4.add(AwardTimeCondition);jp4.add(AwardProjectCondition);jp4.add(AwardTeamCondition);jp4.add(ShowStudentDate);//添加jp5上的组件jp5.add(showStudentMessage);jp5.add(showStudentUser);}// 定义各文本框/** InsertID2, 插入学号文本框* InsertName2, 插入姓名文本框* InsertBorn2, 插入出生文本框* InsertClass2, 插入班级文本框* InsertSex , 插入性别文本框* DeleteID2, 所要删除学号的文本框* UpdateID2, 所要更新学号的文本框* UpdateContent, 更新内容填写文本框* IDCondition, 查询ID文本框* NameCondition, 查询姓名文本框* BornCondition, 查询出生文本框* ClassCondition, 查询班级文本框* SexCondition, 查询性别文本框* */private JTextField InsertID2, InsertName2, InsertBorn2, InsertClass2, InsertSex2,InsertAwardName2, InsertAwardLevel2, InsertAwardTime2,InsertAwardTeam2,InsertAwardProject2,DeleteID2, UpdateID2, UpdateContent, IDCondition, NameCondition, BornCondition, ClassCondition,SexCondition,AwardNameCondition,AwardLevelCondition,AwardTimeCondition,AwardProjectCondition,AwardTeamCondition;//定义显示结果文本域 显示 jp4 的查询结果/** QueryRecordResult, 查询学生信息结果文本域*/private JTextArea QueryRecordResult;private void setTextField() {// jp1 上的文本框InsertID2 = new JTextField();InsertID2.setFont(new Font("宋体", 1, 23));InsertID2.setBounds(210, 40, 200, 35);InsertName2 = new JTextField();InsertName2.setFont(new Font("宋体", 1, 23));InsertName2.setBounds(210, 100, 200, 35);InsertBorn2 = new JTextField();InsertBorn2.setFont(new Font("宋体", 1, 23));InsertBorn2.setBounds(210, 160, 200, 35);InsertClass2 = new JTextField();InsertClass2.setFont(new Font("宋体", 1, 23));InsertClass2.setBounds(210, 220, 200, 35);InsertSex2 = new JTextField();InsertSex2.setFont(new Font("宋体", 1, 23));InsertSex2.setBounds(210, 280, 200, 35);InsertAwardName2 = new JTextField();InsertAwardName2.setFont(new Font("楷体", 1, 22));InsertAwardName2.setBounds(560, 40, 200, 35);InsertAwardLevel2 = new JTextField();InsertAwardLevel2.setFont(new Font("楷体", 1, 22));InsertAwardLevel2.setBounds(560, 100, 200, 35);InsertAwardTime2 = new JTextField();InsertAwardTime2.setFont(new Font("楷体", 1, 22));InsertAwardTime2.setBounds(560, 160, 200, 35);InsertAwardProject2 = new JTextField();InsertAwardProject2.setFont(new Font("楷体", 1, 22));InsertAwardProject2.setBounds(560, 220, 200, 35);InsertAwardTeam2 = new JTextField();InsertAwardTeam2.setFont(new Font("楷体", 1, 22));InsertAwardTeam2.setBounds(560, 280, 200, 35);// jp2 上的文本框DeleteID2 = new JTextField("输入要删除信息的学号");DeleteID2.setFont(new Font("楷体", 1, 25));DeleteID2.setBounds(210, 100, 350, 50);// jp3 上的文本框UpdateID2 = new JTextField();UpdateID2.setFont(new Font("楷体", 1, 20));UpdateID2.setBounds(310, 60, 200, 45);UpdateContent = new JTextField("更新内容");UpdateContent.setFont(new Font("楷体", 0, 22));UpdateContent.setBounds(310, 200, 200, 45);// jp4 上的文本框QueryRecordResult = new JTextArea("查询结果:");QueryRecordResult.setFont(new Font("楷体", 1, 20));//QueryRecordResult.setBounds(30,30,560,260);QueryRecordResult.setEditable(false);//设置选项不可用QueryRecordResult.setLineWrap(true); // 当一行文字过多时自动换行scroll = new JScrollPane(QueryRecordResult); // 添加滚动条scroll.setBounds(30, 30, 560, 260);//JScrollPanescroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); // 当需要垂直滚动条时显示scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);// 当需要水平滚动条时显示IDCondition = new JTextField();IDCondition.setFont(new Font("宋体", 1, 18));IDCondition.setBounds(90, 300, 100, 21);NameCondition = new JTextField();NameCondition.setFont(new Font("宋体", 1, 18));NameCondition.setBounds(90, 330, 100, 21);BornCondition = new JTextField();BornCondition.setFont(new Font("宋体", 1, 18));BornCondition.setBounds(90, 360, 100, 21);ClassCondition = new JTextField();ClassCondition.setFont(new Font("宋体", 1, 18));ClassCondition.setBounds(90, 390, 100, 21);SexCondition = new JTextField();SexCondition.setFont(new Font("宋体", 1, 18));SexCondition.setBounds(90, 420, 100, 21);AwardNameCondition = new JTextField();AwardNameCondition.setFont(new Font("宋体", 1, 18));AwardNameCondition.setBounds(390, 300, 100, 21);AwardLevelCondition = new JTextField();AwardLevelCondition.setFont(new Font("宋体", 1, 18));AwardLevelCondition.setBounds(390, 330, 100, 21);AwardTimeCondition = new JTextField();AwardTimeCondition.setFont(new Font("宋体", 1, 18));AwardTimeCondition.setBounds(390, 360, 100, 21);AwardProjectCondition = new JTextField();AwardProjectCondition.setFont(new Font("宋体", 1, 18));AwardProjectCondition.setBounds(390, 390, 100, 21);AwardTeamCondition = new JTextField();AwardTeamCondition.setFont(new Font("宋体", 1, 18));AwardTeamCondition.setBounds(390, 420, 100, 21);IDCondition.setEditable(false);NameCondition.setEditable(false);BornCondition.setEditable(false);ClassCondition.setEditable(false);SexCondition.setEditable(false);AwardNameCondition.setEditable(false);AwardLevelCondition.setEditable(false);AwardTimeCondition.setEditable(false);AwardProjectCondition.setEditable(false);AwardTeamCondition.setEditable(false);}// 定义选项卡上的嵌板/** jp1, 输入个人信息信息* jp2, 删除个人信息* jp3, 更新个人信息* jp4, 个人信息查询* jp5, 学生录入情况总览* jp6 学生注册情况总览* */private JPanel jp1, jp2, jp3, jp4,jp5;// 设置各面板信息的方法private void setPanel() {jp1 = new JPanel();jp2 = new JPanel();jp3 = new JPanel();jp4 = new JPanel();jp5 = new JPanel();}// 定义选项卡private JTabbedPane Base;// 设置选项卡信息的方法//管理员权限private void setBase() {Base = new JTabbedPane(JTabbedPane.TOP);Base.addTab("添加记录", jp1);Base.addTab("删除记录", jp2);Base.addTab("更新记录", jp3);Base.addTab("信息查询", jp4);Base.addTab("账号管理", jp5);}//学生权限private void setBase2() {Base = new JTabbedPane(JTabbedPane.TOP);Base.addTab("添加记录", jp1);Base.addTab("更新记录", jp3); }// 设置主窗口信息的方法private void setThis() {this.add(Base);this.setTitle("学生信息管理系统");this.setLocation(300, 200);this.setSize(800, 550);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setResizable(false); //窗体大小不可改变this.setVisible(true);}// 设置数据库信息的方法private void setDB() {db = new OperationMysql();// 连接 mysqldb.setDburl("jdbc:mysql://localhost:3306/StudentInfo");// 加载驱动db.setDbdriver("com.mysql.jdbc.Driver");db.setUsername("root");db.setPassword("");}// 定义查询选项/** ID, 选择学号查询* Name, 选择姓名查询* Born, 选择出生查询* Class, 选择班级查询* Sex, 选择性别查询* */private JRadioButton ID, Name, Born, Class, Sex,AwardName,AwardLevel,AwardTime,AwardProject,AwardTeam;// 初始化void initial() {// 给各按钮添加监听器 StudentDate.addMouseListener(this);StudentDateClear.addMouseListener(this);DeleteStudentDate.addMouseListener(this);DeleteStudentDateClear.addMouseListener(this);updateStudentDate.addMouseListener(this);updateStudentDateClear.addMouseListener(this);ShowStudentDate.addMouseListener(this);showStudentMessage.addMouseListener(this);showStudentUser.addMouseListener(this);// 给各复选按钮添加监听器// ID,Name,Born, Class, Sex,Aname,Alevel,Atime,Aproject,AteamID.addItemListener(this);Name.addItemListener(this);Born.addItemListener(this);Class.addItemListener(this);Sex.addItemListener(this);AwardName.addItemListener(this);AwardLevel.addItemListener(this);AwardTime.addItemListener(this);AwardProject.addItemListener(this);AwardTeam.addItemListener(this);}@Overridepublic void mouseClicked(MouseEvent e) {// 添加按钮功能// 点击重置键则清空文本框if (e.getSource().equals(StudentDateClear)) {InsertID2.setText("");InsertID2.setFont(new Font("宋体", 1, 23));InsertName2.setText("");InsertName2.setFont(new Font("宋体", 1, 23));InsertClass2.setText("");InsertClass2.setFont(new Font("宋体", 1, 23));InsertBorn2.setText("");InsertBorn2.setFont(new Font("宋体", 1, 23));InsertSex2.setText("");InsertSex2.setFont(new Font("宋体", 1, 23));InsertAwardName2.setText("");InsertAwardName2.setFont(new Font("宋体", 1, 23));InsertAwardLevel2.setText("");InsertAwardLevel2.setFont(new Font("宋体", 1, 23));InsertAwardTime2.setText("");InsertAwardTime2.setFont(new Font("宋体", 1, 23));InsertAwardProject2.setText("");InsertAwardProject2.setFont(new Font("宋体", 1, 23));InsertAwardTeam2.setText("");InsertAwardTeam2.setFont(new Font("宋体", 1, 23));} else if (e.getSource().equals(showStudentMessage)) {new StudentMessageShow();}else if (e.getSource().equals(showStudentUser)) {new StudentUserShow();}else if (e.getSource().equals(StudentDate)) {// 添加记录功能String InsertStuID = InsertID2.getText();String InsertStuName = InsertName2.getText();String InsertBorn = InsertBorn2.getText();String InsertClass = InsertClass2.getText();String InsertSex = InsertSex2.getText();String InsertAwardName =InsertAwardName2.getText();String InsertAwardLevel =InsertAwardLevel2.getText();String InsertAwardTime =InsertAwardTime2.getText();String InsertAwardProject =InsertAwardProject2.getText();String InsertAwardTeam =InsertAwardTeam2.getText();try {db.setRs(db.executeQuery(InsertStuID));if (!db.getRs().next()) {db.executeInsert(InsertStuID, InsertStuName, InsertBorn, InsertClass, InsertSex,InsertAwardName,InsertAwardLevel,InsertAwardTime,InsertAwardProject,InsertAwardTeam);JOptionPane.showOptionDialog(this, "添加信息成功!", "数据库操作提示",JOptionPane.CLOSED_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, null);} else JOptionPane.showOptionDialog(this, "添加失败", "温馨提示",-1, 1, null, null, null);} catch (Exception exception) {exception.printStackTrace();} finally {db.CloseRS();db.CloseStmt();db.CloseConnection();}} else if (e.getSource().equals(DeleteStudentDateClear)) {// 删除重置功能DeleteID2.setText("");DeleteID2.setFont(new Font("楷体", 1, 25));} else if (e.getSource().equals(DeleteStudentDate)) {// 删除功能String DeleteStuID = DeleteID2.getText();try {db.setRs(db.executeQuery(DeleteStuID));if (db.getRs().next()) {db.executeDelete(DeleteStuID);JOptionPane.showOptionDialog(this, "删除成功!", "数据库操作提示",-1, 1, null, null, null);} else JOptionPane.showOptionDialog(this, "删除失败", "温馨提示",-1, 1, null, null, null);} catch (Exception exception) {exception.printStackTrace();}} else if (e.getSource().equals(updateStudentDateClear)) {// 重置更新框功能UpdateID2.setText("");UpdateID2.setFont(new Font("宋体", 1, 20));UpdateContent.setText("");UpdateContent.setFont(new Font("宋体", 1, 20));} else if (e.getSource().equals(updateStudentDate)) {// 完成更新功能String UpdateStuID = UpdateID2.getText();try {db.setRs(db.executeQuery(UpdateStuID));if (!db.getRs().next()) {JOptionPane.showOptionDialog(this, "没有记录无法更新","温馨提示", JOptionPane.CLOSED_OPTION, JOptionPane.INFORMATION_MESSAGE,null, null, null);} else {String updateItem = null;// 更新选项是姓名if (UpdateItem.getSelectedItem().toString().equals("姓名")) {updateItem = "Name";}// 更新的是出生else if (UpdateItem.getSelectedItem().toString().equals("出生年月")) {updateItem = "Born";}// 更新的是班级else if (UpdateItem.getSelectedItem().toString().equals("所属班级")) {updateItem = "Class";}// 更新的是性别else if (UpdateItem.getSelectedItem().toString().equals("性别")) {updateItem = "Sex";}// 更新的是获奖名称else if (UpdateItem.getSelectedItem().toString().equals("获奖名称")) {updateItem = "AwardName";}// 更新的是获奖等级else if (UpdateItem.getSelectedItem().toString().equals("获奖等级")) {updateItem = "AwardLevel";}// 更新的是获奖时间else if (UpdateItem.getSelectedItem().toString().equals("获奖时间")) {updateItem = "AwardTime";}// 更新的是获奖类别else if (UpdateItem.getSelectedItem().toString().equals("获奖类别")) {updateItem = "AwardProject";}// 更新的是获奖团名else if (UpdateItem.getSelectedItem().toString().equals("获奖团名")) {updateItem = "AwardTeam";}db.executeUpdate(UpdateStuID, updateItem, UpdateContent.getText());JOptionPane.showOptionDialog(this, "更新成功!", "数据库操作提示",-1, 1, null, null, null);}} catch (Exception exception) {exception.printStackTrace();} finally {db.CloseRS();db.CloseStmt();db.CloseConnection();}} else if (e.getSource().equals(ShowStudentDate)) {// 完成查询功能try {// 默认设置各检索条件均为通配符String a = "%", b = "%", c = "%", d = "%", f = "%" , g = "%", h = "%", z = "%", j = "%",k = "%";// 如果 ID 选项被选中,则获得该选项的输入内容if (ID.isSelected() && !IDCondition.getText().trim().isEmpty()) {a = IDCondition.getText();}// 如果 Name 选项被选中,则获得该选项的输入内容if (Name.isSelected() && !NameCondition.getText().trim().isEmpty()) {b = NameCondition.getText();}// 如果 Born 选项被选中,则获得该选项的输入内容if (Born.isSelected() && !BornCondition.getText().trim().isEmpty()) {d = BornCondition.getText();}// 如果 Class 选项被选中,则获得该选项的输入内容if (Class.isSelected() && !ClassCondition.getText().trim().isEmpty()) {f = ClassCondition.getText();}// 如果 Sex 选项被选中,则获得该选项的输入内容if (Sex.isSelected() && !SexCondition.getText().trim().isEmpty()) {c = SexCondition.getText();}// 如果 Aname 选项被选中,则获得该选项的输入内容if (AwardName.isSelected() && !AwardNameCondition.getText().trim().isEmpty()) {g = AwardNameCondition.getText();}// 如果 Alevel 选项被选中,则获得该选项的输入内容if (AwardLevel.isSelected() && !AwardLevelCondition.getText().trim().isEmpty()) {h = AwardLevelCondition.getText();}// 如果 Atime 选项被选中,则获得该选项的输入内容if (AwardTime.isSelected() && !AwardTimeCondition.getText().trim().isEmpty()) {z = AwardTimeCondition.getText();}// 如果 Aproject 选项被选中,则获得该选项的输入内容if (AwardProject.isSelected() && !AwardProjectCondition.getText().trim().isEmpty()) {j = AwardProjectCondition.getText();}// 如果 Ateam选项被选中,则获得该选项的输入内容if (AwardTeam.isSelected() && !AwardTeamCondition.getText().trim().isEmpty()) {k = AwardTeamCondition.getText();}// 根据各选项检索关键字进行查询,并返回结果集db.setRs(db.executeQueryByCondition(a, b, d, f, c, g, h, z, j, k));// 定义结果集中记录条数int i = 0;QueryRecordResult.setText("查询结果:");// 输出结果集记录while (db.getRs().next()) {++i;QueryRecordResult.append("\r\n" + "第" + i + "条记录:" + "\r\n"+ "学号:" + db.getRs().getString(1) + "\r\n"+ "姓名:" + db.getRs().getString(2) + "\r\n"+ "出生:" + db.getRs().getString(3) + "\r\n"+ "班级:" + db.getRs().getString(4) + "\r\n"+ "性别:" + db.getRs().getString(5) + "\r\n"+ "获奖名称:" + db.getRs().getString(6) + "\r\n"+ "获奖级别:" + db.getRs().getString(7) + "\r\n"+ "获奖时间:" + db.getRs().getString(8) + "\r\n"+ "获奖类别:" + db.getRs().getString(9) + "\r\n"+ "获奖团队:" + db.getRs().getString(10) + ("\r\n--------------------------------------"));}QueryRecordResult.setText(QueryRecordResult.getText() +"\r\n" + "共有" + i + "条学生记录");} catch (Exception e1) {e1.printStackTrace();} finally {db.CloseRS();db.CloseStmt();db.CloseConnection();}} }@Overridepublic void mousePressed(MouseEvent e) {}@Overridepublic void mouseReleased(MouseEvent e) {}@Overridepublic void mouseEntered(MouseEvent e) {}@Overridepublic void mouseExited(MouseEvent e) {}@Overridepublic void itemStateChanged(ItemEvent e) {// 如果查询选项 ID 被选中,则可以输入 ID 进行查询if (e.getSource().equals(ID)) {IDCondition.setEditable(ID.isSelected());}// 如果选项姓名被选中,则可以输入姓名进行查询else if (e.getSource().equals(Name)) {NameCondition.setEditable(Name.isSelected());}// 如果出生被选中,则可以输入出生进行查询else if (e.getSource().equals(Born)) {BornCondition.setEditable(Born.isSelected());}// 如果班级选项被选中,则可以输入班级查询else if (e.getSource().equals(Class)) {ClassCondition.setEditable(Class.isSelected());}// 如果性别选项被选中,则可以输入性别来查询else if (e.getSource().equals(Sex)) {SexCondition.setEditable(Sex.isSelected());}// 如果获奖名称选项被选中,则可以输入性别来查询else if (e.getSource().equals(AwardName)) {AwardNameCondition.setEditable(AwardName.isSelected());}// 如果获奖等级选项被选中,则可以输入性别来查询else if (e.getSource().equals(AwardLevel)) {AwardLevelCondition.setEditable(AwardLevel.isSelected());}// 如果获奖时间选项被选中,则可以输入性别来查询else if (e.getSource().equals(AwardTime)) {AwardTimeCondition.setEditable(AwardTime.isSelected());}// 如果获奖类别选项被选中,则可以输入性别来查询else if (e.getSource().equals(AwardProject)) {AwardProjectCondition.setEditable(AwardProject.isSelected());}// 如果获奖团名选项被选中,则可以输入性别来查询else if (e.getSource().equals(AwardTeam)) {AwardTeamCondition.setEditable(AwardTeam.isSelected());}}
}
OperationMysql源代码
package project;import java.sql.*;public class OperationMysql {// 定义数据库连接urlprivate String dburl = null;// 定义数据库连接private Connection conn = null;// 定义数据库状态private PreparedStatement stmt = null;// 定义数据库返回结果集private ResultSet rs = null;// 定义数据库用户名private String username = null;// 定义数据库连接密码private String password = null;// 定义数据库驱动方式private String dbdriver = null;// 设置数据库连接url的方法public void setDburl(String dburl) {this.dburl = dburl;}// 返回当前实例数据库连接urlpublic String getDburl() {return dburl;}// 返回当前实例结果集的方法public ResultSet getRs() {return rs;}// 设置当前实例结果集的方法public void setRs(ResultSet rs) {this.rs = rs;}// 设置数据库用户名的方法public void setUsername(String username) {this.username = username;}// 返回当前实例化数据库用户名public String getUsername() {return username;}// 设置数据库连接的方法public void setPassword(String password) {this.password = password;}// 返回当前实例数据库连接密码public String getPassword() {return password;}// 设置数据库驱动方式的方法public void setDbdriver(String dbdriver) {this.dbdriver = dbdriver;}// 返回当前实例数据库驱动方式的方法public String getDbdriver() {return dbdriver;}// 创建数据库连接的方法Connection CreateConnection(String dburl, String username, String password) throws Exception {setDburl(dburl);setUsername(username);setPassword(password);Class.forName(getDbdriver());// 根据数据库路径、用户名和密码创建连接并返回该连接return DriverManager.getConnection(dburl, username, password);}// 关闭结果集的方法public void CloseRS() {try {rs.close();} catch (SQLException e) {System.out.println("关闭结果集时发生错误!");}}// 关闭状态的方法public void CloseStmt() {try {stmt.close();} catch (SQLException e) {System.out.println("关闭状态时发生错误!");}}// 关闭连接的方法public void CloseConnection() {try {conn.close();} catch (SQLException e) {System.out.println("关闭连接时发生错误!");}}// 增void executeInsert(String InsertID, String InsertName, String InsertBorn, String InsertClass, String InsertSex,String InsertAwardName,String InsertAwardLevel,String InsertAwardTime,String InsertAwardProject,String InsertAwardTeam) throws Exception {try {conn = CreateConnection(getDburl(), getUsername(), getPassword());stmt = conn.prepareStatement("insert into grade values(?,?,?,?,?,?,?,?,?,?)");stmt.setString(1, InsertID);stmt.setString(2, InsertName);stmt.setString(3, InsertBorn);stmt.setString(4, InsertClass);stmt.setString(5, InsertSex);stmt.setString(6, InsertAwardName);stmt.setString(7, InsertAwardLevel);stmt.setString(8, InsertAwardTime);stmt.setString(9, InsertAwardProject);stmt.setString(10, InsertAwardTeam);stmt.executeUpdate();} catch (SQLException ex) {System.err.println(ex.getMessage());}}// 删void executeDelete(String DeleteID) throws Exception {try {conn = CreateConnection(getDburl(), getUsername(), getPassword());stmt = conn.prepareStatement("delete from grade where ID = ?");stmt.setString(1, DeleteID);stmt.executeUpdate();CloseStmt();CloseConnection();} catch (SQLException ex) {System.err.println(ex.getMessage());}}// 查 主键 是否在表中ResultSet executeQuery(String StuID) throws Exception {try {String sql = "select * from grade where ID = ?";conn = CreateConnection(getDburl(), getUsername(), getPassword());stmt = conn.prepareStatement(sql);stmt.setString(1, StuID);rs = stmt.executeQuery();} catch (SQLException e) {System.err.println(e.getMessage());}return rs;}// 改void executeUpdate(String UpdateID, String UpdateItem, String UpdateContent) throws Exception {try {conn = CreateConnection(getDburl(), getUsername(), getPassword());String sql = "update grade set " + UpdateItem + " = ? where ID = ?";stmt = conn.prepareStatement(sql);stmt.setString(1, UpdateContent);stmt.setString(2, UpdateID);stmt.executeUpdate();} catch (SQLException ex) {System.err.println(ex.getMessage());}}// 按条件查询ResultSet executeQueryByCondition(String stuid, String stuname, String Born, String Class, String Sex,String AwardName,String AwardLevel,String AwardTime,String AwardProject,String AwardTeam) throws Exception {try {String sql = "select * from grade where ID like ? and Name like ? and Born like ? " +"and Class like ? and Sex like ?and AwardName like ?"+ "and AwardLevel like ?and AwardTime like ?"+ "and AwardProject like ?and AwardTeam like ? order by ID asc";conn = CreateConnection(getDburl(), getUsername(), getPassword());stmt = conn.prepareStatement(sql);if (stuid.equals("%")) {stmt.setString(1, "%");} else {stmt.setString(1, "%" + stuid + "%");}if (stuname.equals("%")) {stmt.setString(2, "%");} else {stmt.setString(2, "%" + stuname + "%");}if (Born.equals("%")) {stmt.setString(3, "%");} else {stmt.setString(3, "%" + Born + "%");}if (Class.equals("%")) {stmt.setString(4, "%");} else {stmt.setString(4, "%" + Class + "%");}if (Sex.equals("%")) {stmt.setString(5, "%");} else {stmt.setString(5, "%" + Sex+ "%");}if (AwardName.equals("%")) {stmt.setString(6, "%");} else {stmt.setString(6, "%" + AwardName+ "%");}if (AwardLevel.equals("%")) {stmt.setString(7, "%");} else {stmt.setString(7, "%" + AwardLevel+ "%");}if (AwardTime.equals("%")) {stmt.setString(8, "%");} else {stmt.setString(8, "%" + AwardTime+ "%");}if (AwardProject.equals("%")) {stmt.setString(9, "%");} else {stmt.setString(9, "%" + AwardProject+ "%");}if (AwardTeam.equals("%")) {stmt.setString(10, "%");} else {stmt.setString(10, "%" + AwardTeam+ "%");}rs = stmt.executeQuery();} catch (SQLException ex) {System.err.println(ex.getMessage());}return rs;}}
StartMysql源代码
package project;public class StartMySql {// 启动登录界面public static void main(String[] args) {new Login();}
}
StudentMessage源代码
package project;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Vector;import javax.swing.JOptionPane;public class StudentMessage {// 得到数据库表数据public static Vector getRows(){String sql_url = "jdbc:mysql://localhost:3306/StudentInfo"; String name = "root"; //用户名String password = ""; //密码Connection conn;PreparedStatement preparedStatement = null;Vector rows = null;Vector columnHeads = null;try {Class.forName("com.mysql.jdbc.Driver"); //连接驱动conn = DriverManager.getConnection(sql_url, name, password); //连接数据库preparedStatement = conn.prepareStatement("select * from grade");ResultSet result1 = preparedStatement.executeQuery();if(result1.wasNull())JOptionPane.showMessageDialog(null, "结果集中无记录");rows = new Vector();ResultSetMetaData rsmd = result1.getMetaData();while(result1.next()){rows.addElement(getNextRow(result1,rsmd));}} catch (ClassNotFoundException e) {// TODO Auto-generated catch blockSystem.out.println("未成功加载驱动。");e.printStackTrace();} catch (SQLException e) {// TODO Auto-generated catch blockSystem.out.println("未成功打开数据库。");e.printStackTrace();}return rows;}// 得到数据库表头public static Vector getHead(){String sql_url = "jdbc:mysql://localhost:3306/StudentInfo";String name = "root"; //用户名String password = ""; //密码Connection conn;PreparedStatement preparedStatement = null;Vector columnHeads = null;try {Class.forName("com.mysql.jdbc.Driver"); //连接驱动conn = DriverManager.getConnection(sql_url, name, password); //连接数据库if(!conn.isClosed())System.out.println("成功连接数据库");preparedStatement = conn.prepareStatement("select * from grade");ResultSet result1 = preparedStatement.executeQuery();boolean moreRecords = result1.next();if(!moreRecords)JOptionPane.showMessageDialog(null, "结果集中无记录");columnHeads = new Vector();ResultSetMetaData rsmd = result1.getMetaData();for(int i = 1; i <= rsmd.getColumnCount(); i++)columnHeads.addElement(rsmd.getColumnName(i));} catch (ClassNotFoundException e) {// TODO Auto-generated catch blockSystem.out.println("未成功加载驱动。");e.printStackTrace();} catch (SQLException e) {// TODO Auto-generated catch blockSystem.out.println("未成功打开数据库。");e.printStackTrace();}return columnHeads;}// 得到数据库中下一行数据private static Vector getNextRow(ResultSet rs,ResultSetMetaData rsmd) throws SQLException{Vector currentRow = new Vector();for(int i = 1; i <= rsmd.getColumnCount(); i++){currentRow.addElement(rs.getString(i));}return currentRow;}}
五、 数据库
grade表sql语句
CREATE TABLE `grade` (`ID` int(11) NOT NULL AUTO_INCREMENT,`Name` varchar(255) DEFAULT NULL,`Born` int(11) DEFAULT NULL,`Class` varchar(255) DEFAULT NULL,`Sex` varchar(255) DEFAULT NULL,`AwardName` varchar(255) DEFAULT NULL,`AwardLevel` varchar(255) DEFAULT NULL,`AwardTime` varchar(255) DEFAULT NULL,`AwardProject` varchar(255) DEFAULT NULL,`AwardTeam` varchar(255) DEFAULT NULL,PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
user表sql语句
CREATE TABLE `user` (`ID` varchar(255) NOT NULL,`Password` varchar(255) DEFAULT NULL,PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
六、实践目标及任务要求
目标:
使用GUI图形用户界面及数据库实现学生信息管理系统,该系统旨在实现学生信息的管理,并根据需要进行相应的数据统计
任务要求
1、学生功能
(1)基本信息管理(学号、姓名、性别、出生年月、所在班级;
(2)获奖信息管理,如:学科竞赛获奖信息(竞赛名称、获奖等级、竞赛级别、竞赛类别、参赛成员、竞赛时间等)、其他获奖信息(获奖名称、获奖级别、获奖时间等);
(3)根据基本信息以窗体的形式展示学生的全部信息;
2、管理员功能
(1)用户管理:学生、管理员;
(2)根据选择的学生以窗体的形式展示学生的全部信息;
(3)查询所有学生信息,或根据条件查询学生信息;
(4)分别学生各级别的竞赛和获奖信息,及数量。
七、交流
包运行、实践报告
扣:969060742