【记录贴】数据库课程设计——学生信息管理系统
生活随笔
收集整理的這篇文章主要介紹了
【记录贴】数据库课程设计——学生信息管理系统
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前言
記錄下學習的點點滴滴,留下屬于我的足跡。
以此篇記錄我的第一次課程設計。
課設實現
一、課程設計題目
題目一 學生信息管理系統二、總體設計
原理及工具
JAVA的前端搭建:JAVA GUI MySQL的數據庫后端搭建: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;} }結果
基本上實現了數據庫的基本操作和簡單的審計功能。
但是,但是!存在一些小小的問題,比如所有學生必須有獎勵又有處罰才能在“學生信息查詢”中被找到,所以我又偷偷摸摸在前面的查詢表格中加入了查詢功能,其實可以把“學生信息查詢”的表格簡化,在其他表格中構建如老師案例的表。又或者在沒有處罰和獎勵的情況下強制填入無(還有待改良)。
效果圖
小結
不管怎么說,這一次的課設確實讓我學到了很多東西,雖然自己還是菜菜的,不過問題不大,在今后的學習生活中,還要繼續努力哦!
源代碼
鏈接:https://pan.baidu.com/s/1q3mN5a6fhzCZUrFlFd3HFA
提取碼:1lfb
總結
以上是生活随笔為你收集整理的【记录贴】数据库课程设计——学生信息管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用PHP写一个学生学籍管理系统
- 下一篇: java信息管理系统总结_java实现科