1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 【记录贴】数据库课程设计——学生信息管理系统

【记录贴】数据库课程设计——学生信息管理系统

时间:2018-12-01 15:32:12

相关推荐

【记录贴】数据库课程设计——学生信息管理系统

前言

记录下学习的点点滴滴,留下属于我的足迹。

以此篇记录我的第一次课程设计。

课设实现

一、课程设计题目

题目一 学生信息管理系统

二、总体设计

原理及工具

JAVA的前端搭建:JAVA GUIMySQL的数据库后端搭建:DDL,DQL,DML,DCL。数据库与前端的连接:mysql-connector-java等

模块介绍

该学生信息管理系统主要分为6个模块:①身份验证模块②新生信息输入模块③教务信息输入之学籍变更模块④教务信息输入之奖学金评定模块⑤教务信息输入之处罚记录模块⑥个人信息查询修改模块

设计步骤

①构建身份验证登录窗口;②设计登陆界面与信息变更查询的选择框界面的跳转;③设计选择框与模块2、3、4、5、6的跳转;④完善各个界面的功能设计;⑤美化界面。

详细设计

需求分析:

1.系统需求分析

学校每年都有新生入学、老生毕业,还有其他各种人事变动。如何有效地管理这些学生 的信息,帮助学校和老师掌握学生的情况,这就是学生信息管理系统需要完成的功能。

2.数据库需求分析

可以列出以下记录学生信息所需的数据项和数据结构:学生:学号、姓名、性别、生日、籍贯、所在院系、所在班级。处罚记录:记录号、级别、处罚对象、记录时间、详细描述、是否生效。 奖励记录:记录号、级别、奖励对象、记录时间、详细描述。学籍变更记录:记录号、变更情况、记录对象、记录时间、详细描述。所需的外部数据支持:班级:班级编号、班级名称、所属院系、班长。院系:代码、名称。

功能分析

本系统主要的功能是收集学生的个人信息,以便向教师提供每个学生在校的情况。系统 的主要功能有:

①学生个人信息输入,包括:姓名、性别、院系、生日、籍贯、生源所在地等。

②学生流动情况的输入,包括:转系、休学、复学、退学、毕业。

③奖惩情况的输入。

④学生个人情况查询和修改,包括流动情况和奖罚情况。

概念模型(E-R模型)

逻辑设计

物理设计(MySQL后端开发)

部分代码(其他类似)

构建student表,设置外键,建立级联:

create table student(studentid char(15) not null primary key,name char(10) not null,sex char(2) not null,class char(4) not null,department char(2) not null,birthday date null,native_place char(10) null,constraint fk_class foreign key (class) references class(id) on update cascade on delete cascade,constraint fk_department foreign key (department) references department(id) on update cascade on delete cascade);

前端开发(Java):

关键代码:

定性查询、将数据存入JTable表:

憨憨如我,一开始没想这么多,建立了一个超大的表

//定义Vector title, title1, title2, title3, title4 = null;JTable table = null;JScrollPane scrollpane = null;

// 建表title = new Vector();title1 = new Vector();title2 = new Vector();title3 = new Vector();title4 = new Vector();title1.add("学号");title1.add("姓名");title1.add("性别");title1.add("籍贯");title1.add("学籍变更");title1.add("记录时间");title1.add("描述");title1.add("奖励");title1.add("记录时间");title1.add("描述");title1.add("处罚");title1.add("记录时间");title1.add("描述");title1.add("是否生效");table = new JTable(title, title1);table.setPreferredScrollableViewportSize(new Dimension(450, 160));scrollpane = new JScrollPane(table);scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

public void queryProcess(String sQueryField) {try {// 建立查询条件String sql1 = "select student.studentid,student.name,student.sex,student.class,student.department,student.birthday,student.native_place,\r\n"+ "change_code.description4,change_al.rec_time1,change_al.description1,\r\n"+ "reward_levels.description5,reward.rec_time2,reward.description2,\r\n"+ "punish_levels.description6,punishment.rec_time3,punishment.description3,punishment.enable\r\n"+ "from student,change_al,reward,punishment,change_code,reward_levels,punish_levels\r\n"+ "where student.studentid=reward.studentid and student.studentid=change_al.studentid and student.studentid=punishment.studentid \r\n"+ " and change_al.change_al=change_code.code and reward.levels=reward_levels.code and punishment.levels=punish_levels.code \r\n"+ " and ";String queryFieldStr = jCBSelectQueryFieldTransfer(box_choose);sql1 = sql1 + queryFieldStr + "='" + sQueryField + "';";System.out.println("queryProcess(). sql = " + sql1);db.connect();ResultSet rs1 = db.executeQuery(sql1);// 将查询获得的记录数据,转换成适合生成JTable的数据形式title.clear();while (rs1.next()) {Vector v = new Vector();v.add(rs1.getString("studentid"));v.add(rs1.getString("name"));v.add(rs1.getString("sex"));v.add(rs1.getString("birthday"));v.add(rs1.getString("native_place"));v.add(rs1.getString("description4"));v.add(rs1.getString("rec_time1"));v.add(rs1.getString("description1"));v.add(rs1.getString("description5"));v.add(rs1.getString("rec_time2"));v.add(rs1.getString("description2"));v.add(rs1.getString("description6"));v.add(rs1.getString("rec_time3"));v.add(rs1.getString("description3"));v.add(rs1.getString("enable"));title.add(v);}table.updateUI();db.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 class login {public login() {//设置窗口JFrame jf = new JFrame();// jf.setResizable(false);jf.setSize(580, 350);jf.setLocation(20, 20);jf.setLayout(new BorderLayout());//定义组件JLabel label1 = new JLabel("账户 :");//设置账户label1.setFont(new Font("Dialog", 1, 15));label1.setForeground(Color.BLACK);JLabel label2 = new JLabel("密码 :");//设置密码label2.setFont(new Font("Dialog", 1, 15));label2.setForeground(Color.BLACK);JTextField text = new JTextField(13);//设置账户文本框text.setBorder(BorderFactory.createLineBorder(Color.darkGray));JPasswordField password = new JPasswordField(13);//设置密码文本框password.setBorder(BorderFactory.createLineBorder(Color.darkGray));JButton button = new JButton("登录");//设置登录按钮button.setBorderPainted(false);button.setForeground(Color.GRAY);button.setBackground(Color.ORANGE);// 设置背景面板JPanel panel1 = new JPanel() {public void paintComponent(Graphics g) {super.paintComponent(g);ImageIcon image = new ImageIcon("D:\\eclipse\\workspace\\学生信息管理系统\\Pictures\\8463593.jpg");g.drawImage(image.getImage(), 0, 0, getWidth(), getHeight(), image.getImageObserver());}};panel1.setLayout(null);//取消背景板布局//加入组件panel1.add(label1);panel1.add(label2);panel1.add(text);panel1.add(password);panel1.add(button);//设置组件位置label1.setBounds(180, 200, 40, 20);text.setBounds(230, 200, 125, 20);label2.setBounds(180, 230, 40, 20);password.setBounds(230, 230, 125, 20);button.setBounds(260, 276, 60, 20);//加入窗口jf.add(panel1);jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);jf.setVisible(true);//为登录按钮设置监听器button.addMouseListener(new MouseAdapter() {public void mouseClicked(MouseEvent e) {String inputstr1 = text.getText().trim();String inputstr2 = password.getText().trim();if (inputstr1.equals("") && inputstr2.equals("")) {jf.dispose();new ManagerFrame();} else {JOptionPane.showConfirmDialog(null, "账户或密码错误", "温馨提示", JOptionPane.CLOSED_OPTION);}}});}public static void main(String[] args) {new login();}}

焦点获取(花里胡哨

jf.addWindowFocusListener(new WindowFocusListener() {@Overridepublic void windowLostFocus(WindowEvent e) {// TODO Auto-generated method stubjf.dispose();}@Overridepublic void windowGainedFocus(WindowEvent e) {// TODO Auto-generated method stubSystem.out.println("点击窗口区域");}});

审计(简易版

public void Audit(String sql) throws Exception {// TODO Auto-generated method stubFile file=new File("D:\\eclipse\\workspace\\学生信息管理系统\\Audit\\数据库审计文档.txt");FileOutputStream out=new FileOutputStream(file,true);String str=sql;//分隔符String strline="***********************************\r\n";str+="\r\n";//时间Date date =new Date();SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒:\n");String time=sdf.format(date);out.write(time.getBytes());out.write(str.getBytes());out.write(strline.getBytes());out.close();}

前后端的连接

public class DbProcess{Connection connection = null;ResultSet rs = null;//mysql数据库urlString userMySql="root"; String passwordMySql="数据库的密码";//String urlMySql="jdbc:mysql://localhost:3306/db_test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT";String urlMySql = "jdbc:mysql://localhost:3306/db_test?user="+userMySql+"&password="+passwordMySql + "&useUnicode=true&characterEncoding=gbk&useSSL=false&serverTimezone=GMT";//如果是使用MySQL5.0版本,则//String urlMySql = "jdbc:mysql://localhost:3306/db_test?user="+userMySql+"&password="+passwordMySql + "&useUnicode=true&characterEncoding=gbk";//sqlserver数据库url//String urlSqlServer = "jdbc:sqlserver://localhost:1433;integratedSecurity=true;DatabaseName=InfoDb";public DbProcess() {try {//mysql数据库设置驱动程序类型Class.forName("com.mysql.cj.jdbc.Driver"); System.out.println("mysql数据库驱动加载成功");//如果是MySQL5.0版本,则去掉.cj//sqlserver数据库设置驱动程序类型//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//System.out.println("sqlserver数据库驱动加载成功");}catch(java.lang.ClassNotFoundException e) {e.printStackTrace();}}public void connect(){try{//mysql数据库connection = DriverManager.getConnection(urlMySql); //sqlserver数据库//connection = DriverManager.getConnection(urlSqlServer);if(connection!=null){System.out.println("数据库连接成功");}}catch(Exception e){e.printStackTrace();}}public void disconnect(){try{if(connection != null){System.out.println("数据库连接断开");connection.close();connection = null;}}catch(Exception e){e.printStackTrace();}}public ResultSet executeQuery(String sql) {try {System.out.println("executeQuery(). sql = " + sql);PreparedStatement pstm = connection.prepareStatement(sql);// 执行查询rs = pstm.executeQuery();} catch(SQLException ex) { ex.printStackTrace();}return rs;}//插入//executeUpdate 的返回值是一个整数,指示受影响的行数(即更新计数)。//executeUpdate用于执行 INSERT、UPDATE 或 DELETE 语句//以及 SQL DDL(数据定义语言)语句,例如 CREATE TABLE 和 DROP TABLE。//执行增、删、改语句的方法public int executeUpdate(String sql) {int count = 0;connect();try {Statement stmt = connection.createStatement();count = stmt.executeUpdate(sql);} catch(SQLException ex) { System.err.println(ex.getMessage());}disconnect();return count;}}

结果

基本上实现了数据库的基本操作和简单的审计功能。

但是,但是!存在一些小小的问题,比如所有学生必须有奖励又有处罚才能在“学生信息查询”中被找到,所以我又偷偷摸摸在前面的查询表格中加入了查询功能,其实可以把“学生信息查询”的表格简化,在其他表格中构建如老师案例的表。又或者在没有处罚和奖励的情况下强制填入无(还有待改良)。

效果图

小结

不管怎么说,这一次的课设确实让我学到了很多东西,虽然自己还是菜菜的,不过问题不大,在今后的学习生活中,还要继续努力哦!

源代码

链接:/s/1q3mN5a6fhzCZUrFlFd3HFA

提取码:1lfb

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。