├── .DS_Store ├── README.md ├── lib └── mysql-connector-java-5.1.7-bin.jar └── src └── student ├── SQL.java ├── land.java └── system.java /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaGraduationProject/StudentDormitoryManagementSystem3/8ea9d98cc4de45a228993f36de9955f57986ebb4/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 全目录 2 | 3 | [更多系统、论文,供君选择 ~~>](https://www.yuque.com/wisebit/blog) 4 | 5 | # 318.StudentDormitoryManagementSystem3 6 | 7 |

群: 983063232(入群获取sql文件)

8 |

QQ: 206157502(入群获取sql文件)

9 | 10 |

318.学生宿舍管理系统

11 | 12 | 13 |

14 | 15 | 16 |

17 | 18 | # 简介 19 | 20 | > 本代码来源于网络,仅供学习参考使用,请入群(983063232)后联系群主索要sql文件! 21 | > 22 | > 提供1.远程部署/2.修改代码/3.设计文档指导/4.框架代码讲解等服务 23 | > 24 | > 管理员: admin 密码: 123456 25 | 26 | 27 | # 环境 28 | 29 | - IntelliJ IDEA 2021.3 30 | 31 | - Mysql 5.7.26 32 | 33 | - Tomcat 7.0.73 34 | 35 | - JDK 1.8 36 | 37 | 38 | 39 | 40 | ## 缩略图 41 | 42 | ![](https://bitwise.oss-cn-heyuan.aliyuncs.com/2024/9/10/f8efd646-47d6-416b-9252-155cfbf8a34c.png) 43 | ![](https://bitwise.oss-cn-heyuan.aliyuncs.com/2024/9/10/6dc66576-9ba7-4883-9838-4642869fca04.png) 44 | ![](https://bitwise.oss-cn-heyuan.aliyuncs.com/2024/9/10/13484568-b989-48ff-a459-393d68ace104.png) 45 | ![](https://bitwise.oss-cn-heyuan.aliyuncs.com/2024/9/10/9100333d-f800-45cc-a1ad-c966247389e0.png) 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /lib/mysql-connector-java-5.1.7-bin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaGraduationProject/StudentDormitoryManagementSystem3/8ea9d98cc4de45a228993f36de9955f57986ebb4/lib/mysql-connector-java-5.1.7-bin.jar -------------------------------------------------------------------------------- /src/student/SQL.java: -------------------------------------------------------------------------------- 1 | //sql代码 2 | package student; 3 | 4 | import java.sql.Connection; 5 | import java.sql.DriverManager; 6 | import java.sql.ResultSet; 7 | import java.sql.SQLException; 8 | import java.sql.Statement; 9 | import java.util.Vector; 10 | 11 | public class SQL { 12 | public Connection conn; 13 | //Connection接口是构造类的基础,其他接口出现需要它 14 | public Statement st; 15 | //Statement是执行数据库操作的接口,其对象也就是st用于执行简单的sql语句 16 | public ResultSet rs; 17 | //ResultSet结果集接口 18 | 19 | //获取链接 20 | public Connection getConn() throws SQLException, ClassNotFoundException { 21 | String driverClassName = "com.mysql.jdbc.Driver"; 22 | String url = "jdbc:mysql://127.0.0.1:3306/graduation_318_student?useUnicode=true&characterEncoding=UTF-8&tinyInt1isBit=false"; 23 | //数据库默认端口号,一般为3306(我的可能特殊,可以改成3306)学生是数据库名字 24 | String user = "root"; //登录用的用户名,下面是密码,可以自己改。 25 | String password = "123456"; 26 | try { 27 | Class.forName(driverClassName); 28 | conn = DriverManager.getConnection(url, user, password); 29 | System.out.println("数据库连接成功"); 30 | } catch (SQLException ex1) { 31 | System.out.println("数据库连接失败"); 32 | } 33 | return conn; 34 | } 35 | 36 | //关闭链接 37 | //几个接口就捕捉异常几次,(用其对象) 38 | public void Close() { 39 | try { 40 | rs.close(); 41 | } catch (SQLException e) { 42 | e.printStackTrace(); 43 | } 44 | try { 45 | st.close(); 46 | } catch (SQLException e1) { 47 | e1.printStackTrace(); 48 | } 49 | try { 50 | conn.close(); 51 | } catch (SQLException e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | 56 | //登录 57 | public int landing(String name1, String password1) { 58 | int num = 0; 59 | String sql = "select *from user"; 60 | try { 61 | getConn(); 62 | st = conn.createStatement(); 63 | rs = st.executeQuery(sql);//Statement接口对象rs执行上面的查询用户表sql操作 64 | while (rs.next()) { 65 | String name = rs.getString(1).trim();//得到用户名 66 | //trim函数清除单元格中的空格 67 | String password = rs.getString(2).trim();//得到密码 68 | if (name.equals(name1) && password.equals(password1)) { 69 | num = 1;//a 70 | } 71 | 72 | } 73 | } catch (SQLException e) { 74 | // TODO: handle exception 75 | } catch (ClassNotFoundException e) { 76 | // TODO Auto-generated catch block 77 | e.printStackTrace(); 78 | //查询异常 固定的 79 | } 80 | Close();//关闭 81 | return num;//注意初始是0,如果用户名和密码符合就变成了1在上面a处,后面同理 82 | } 83 | 84 | //查询 85 | public Vector> query(String tableName, int column) { 86 | int num = 0; 87 | String sql = "select * from " + tableName; 88 | Vector> data = new Vector>();//利用vector创建存数据对象 89 | try { 90 | getConn(); 91 | st = conn.createStatement(); 92 | rs = st.executeQuery(sql); 93 | while (rs.next()) { 94 | Vector rowdata = new Vector(); 95 | for (num = 1; num <= column; num++) { 96 | rowdata.add(rs.getString(num)); 97 | } 98 | data.add(rowdata); 99 | } 100 | } catch (SQLException ex1) { 101 | System.out.println("失败" + ex1); 102 | } catch (ClassNotFoundException e) { 103 | // TODO Auto-generated catch block 104 | e.printStackTrace();//也是捕捉异常,后面同理 105 | } 106 | Close(); 107 | return data; 108 | } 109 | 110 | //删除 111 | public int delete(String sql) { 112 | int num = 0; 113 | try { 114 | getConn(); 115 | st = conn.createStatement(); 116 | num = st.executeUpdate(sql); 117 | } catch (SQLException e) { 118 | // TODO: handle exception 119 | } catch (ClassNotFoundException e) { 120 | // TODO Auto-generated catch block 121 | e.printStackTrace(); 122 | } 123 | Close(); 124 | return num; 125 | } 126 | 127 | //保存 128 | public Vector> Save(String[] sqlvalue, String tableName, int row, int column) { 129 | Vector> data = new Vector>(); 130 | try { 131 | getConn(); 132 | st = conn.createStatement(); 133 | st.executeUpdate("delete from " + tableName); 134 | for (int i = 0; i < row; i++) { 135 | st.executeUpdate(sqlvalue[i].toString()); 136 | } 137 | data = query(tableName, column); 138 | 139 | } catch (SQLException e) { 140 | // TODO: handle exception 141 | } catch (ClassNotFoundException e) { 142 | // TODO Auto-generated catch block 143 | e.printStackTrace(); 144 | } 145 | return data; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/student/land.java: -------------------------------------------------------------------------------- 1 | //登录界面 以及按钮代码 2 | package student; 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.ActionEvent; 6 | import java.awt.event.ActionListener; 7 | public class land extends JFrame implements ActionListener{ 8 | 9 | private static final long serialVersionUID = 1L; 10 | //不手动修改的话 java默认serialVersionUID属性就是1L. 11 | static SQL sq; 12 | JFrame frame = new JFrame("用户登陆"); 13 | JPanel panel = (JPanel)frame.getContentPane(); 14 | JPanel panel2 = new JPanel(); 15 | JButton buttonLand = new JButton("登陆"); 16 | //JButton就是按钮,后面同理,这里就是 定义登陆按钮 17 | ImageIcon img1 = new ImageIcon("D://1.jpg"); 18 | //ImageIcon是图标,括号中的是图标图片的地址,可以自己更改想要的图片地址为括号里的,也可以换地址。 19 | JLabel background = new JLabel(img1); 20 | JLabel label1 = new JLabel("账号:"); 21 | JLabel label2 = new JLabel("密码:"); 22 | JTextField textName = new JTextField(10); 23 | JPasswordField textPassword = new JPasswordField(20); 24 | //JTextField与JPasswordField都是Java swing的组件,后者是前者子类,后者显示*(例如输入123 出来是***) 25 | public land() { 26 | frame.setSize(500,300);//设置组件大小,setsize(a,b),a是长,b是宽 27 | frame.setVisible(true);//也是组件,表示可见性,true即可见 28 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 29 | //setDefaultCloseOperation方法用于设置窗口默认关闭操作 30 | frame.setLocationRelativeTo(null); 31 | frame.setResizable(false);//窗口是否可以调节大小,false 不能 32 | //背景图 33 | background.setBounds(0, 0,img1.getIconWidth(),img1.getIconHeight()); 34 | frame.getLayeredPane().add(background,new Integer(Integer.MIN_VALUE)); 35 | //内容窗板 36 | panel.setOpaque(false); 37 | panel.setLayout(null); 38 | panel.add(buttonLand); 39 | buttonLand.setBounds(360, 100, 120, 35); 40 | //setBounds(int x,y,width,height) x,y是起始坐标,其余是宽度和高度 41 | //setBounds用来设置变量的上下姐 42 | buttonLand.addActionListener(this); 43 | panel.add(label1); 44 | label1.setBounds(90, 50, 70, 60); 45 | label1.setForeground(Color.CYAN); 46 | panel.add(label2); 47 | label2.setBounds(90, 120, 70, 60); 48 | label2.setForeground(Color.CYAN); 49 | panel.add(textName); 50 | textName.setBounds(140, 65, 180, 30); 51 | panel.add(textPassword); 52 | textPassword.setBounds(140, 130, 180, 30); 53 | } 54 | @Override 55 | public void actionPerformed(ActionEvent e) { 56 | // TODO Auto-generated method stub 57 | if((JButton)e.getSource()== buttonLand) 58 | { 59 | 60 | String name = textName.getText().trim(); 61 | String password = String.valueOf(textPassword.getPassword()).trim(); 62 | int num = sq.landing(name, password); 63 | if(num==1) 64 | { 65 | JOptionPane.showMessageDialog(frame, "欢迎进入学生管理系统!","提示:",JOptionPane.PLAIN_MESSAGE); 66 | system system = new system(); 67 | frame.dispose(); 68 | } 69 | else 70 | { 71 | JOptionPane.showMessageDialog(frame, "账号或者密码错误!","提示:",JOptionPane.ERROR_MESSAGE); 72 | } 73 | } 74 | } 75 | public static void main(String[] args) { 76 | new land(); 77 | sq = new SQL(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/student/system.java: -------------------------------------------------------------------------------- 1 | //增加数据:点击增加按钮会出现一空白行,填写完点击保存即可保存(更新)数据:直接在表中进行相应的操作,再点击保存即可,删除数据:选择某行,点击删除按钮即可 2 | //系统管理界面代码 3 | package student; 4 | 5 | import javax.swing.*; 6 | import javax.swing.event.ChangeEvent; 7 | import javax.swing.event.ChangeListener; 8 | import javax.swing.table.DefaultTableModel; 9 | import java.awt.*; 10 | import java.awt.event.ActionEvent; 11 | import java.awt.event.ActionListener; 12 | import java.util.Vector; 13 | 14 | public class system extends JFrame implements ChangeListener, ActionListener { 15 | /** 16 | * 17 | */ 18 | private static final long serialVersionUID = 1L;//和land中的一样固定,后面很多前面有注释,可以翻翻前面 19 | static SQL sq = new SQL(); 20 | JFrame frame = new JFrame(); 21 | JTabbedPane paneParent = new JTabbedPane(); 22 | JPanel paneWelcome = new JPanel(); 23 | JPanel paneStudent = new JPanel(); 24 | JPanel paneDormitory = new JPanel(); 25 | JPanel paneButton = new JPanel(); 26 | JLabel labelWelcome = new JLabel("学生宿舍管理系统"); 27 | JLabel labelWelcome2 = new JLabel("您的身份为系统管理员"); 28 | DefaultTableModel tableModel; 29 | JTable table; 30 | JScrollPane s; 31 | JButton buttonSave = new JButton("保存");//Jbutton都是按钮 32 | JButton buttonDelete = new JButton("删除"); 33 | JButton buttonIncrease = new JButton("增加"); 34 | Vector dataTitle = new Vector(); 35 | Vector TitleDormitor = new Vector(); 36 | Vector> data = new Vector>(); 37 | 38 | public system() { 39 | frame.setSize(700, 600); 40 | frame.setVisible(true); 41 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 42 | frame.setLocationRelativeTo(null); 43 | frame.setResizable(false); 44 | frame.setLayout(null); 45 | //选项卡 46 | frame.add(paneParent); 47 | paneParent.setBounds(0, 0, 500, 600); 48 | frame.add(paneButton); 49 | paneButton.setBounds(510, 0, 200, 600); 50 | paneParent.addTab("学生管理系统", null, paneWelcome, null); 51 | paneParent.addTab("学生信息", null, paneStudent, "学生信息"); 52 | paneParent.addTab("宿舍信息", null, paneDormitory, "宿舍信息"); 53 | //欢迎页 54 | paneWelcome.setLayout(null); 55 | paneWelcome.add(labelWelcome); 56 | labelWelcome.setBounds(50, 150, 500, 100); 57 | labelWelcome.setFont(new java.awt.Font("Dialog", 1, 40)); 58 | labelWelcome.setForeground(Color.blue); 59 | paneWelcome.add(labelWelcome2); 60 | labelWelcome2.setBounds(60, 300, 500, 40); 61 | labelWelcome2.setFont(new java.awt.Font("Dialog", 1, 30)); 62 | labelWelcome2.setForeground(Color.BLUE); 63 | //表格 64 | dataTitle.add("学号"); 65 | dataTitle.add("姓名"); 66 | dataTitle.add("性别"); 67 | dataTitle.add("专业"); 68 | dataTitle.add("宿舍号"); 69 | dataTitle.add("入住时间"); 70 | TitleDormitor.add("宿舍号"); 71 | TitleDormitor.add("宿舍电话"); 72 | tableModel = new DefaultTableModel(data, dataTitle); 73 | table = new JTable(tableModel); 74 | s = new JScrollPane(table); 75 | paneStudent.setLayout(null); 76 | paneStudent.add(s); 77 | s.setBounds(5, 10, 500, 510); 78 | //按钮 79 | paneButton.setLayout(null); 80 | paneButton.add(buttonSave); 81 | buttonSave.setBounds(25, 30, 100, 30); 82 | paneParent.addChangeListener(this); 83 | paneButton.add(buttonDelete); 84 | buttonDelete.setBounds(25, 80, 100, 30); 85 | paneButton.add(buttonIncrease); 86 | buttonIncrease.setBounds(25, 130, 100, 30); 87 | buttonSave.addActionListener(this); 88 | buttonDelete.addActionListener(this); 89 | buttonIncrease.addActionListener(this); 90 | buttonDelete.setVisible(false); 91 | buttonSave.setVisible(false); 92 | buttonIncrease.setVisible(false); 93 | } 94 | 95 | //选项卡事件 96 | @Override 97 | public void stateChanged(ChangeEvent e) { 98 | // TODO Auto-generated method stub 99 | if (((JTabbedPane) e.getSource()).getSelectedIndex() == 0) { 100 | buttonDelete.setVisible(false); 101 | buttonSave.setVisible(false); 102 | buttonIncrease.setVisible(false); 103 | } 104 | if (((JTabbedPane) e.getSource()).getSelectedIndex() == 1) { 105 | buttonDelete.setVisible(true); 106 | buttonSave.setVisible(true); 107 | buttonIncrease.setVisible(true); 108 | paneStudent.add(s); 109 | data = sq.query("studentinfo", 6); 110 | //System.out.println(data); 111 | tableModel.setDataVector(data, dataTitle); 112 | } 113 | if (((JTabbedPane) e.getSource()).getSelectedIndex() == 2) { 114 | buttonDelete.setVisible(true); 115 | buttonSave.setVisible(true); 116 | buttonIncrease.setVisible(true); 117 | paneDormitory.setLayout(null); 118 | paneDormitory.add(s); 119 | s.setBounds(5, 10, 500, 510); 120 | data = sq.query("dormitory", 2); 121 | //System.out.println(data); 122 | tableModel.setDataVector(data, TitleDormitor); 123 | } 124 | 125 | } 126 | 127 | //按钮事件 128 | @Override 129 | public void actionPerformed(ActionEvent e) { 130 | // TODO Auto-generated method stub 131 | 132 | String tableName = null; 133 | String key1 = null; 134 | if ((JButton) e.getSource() == buttonDelete) { 135 | if (paneParent.getSelectedIndex() == 1) { 136 | tableName = "studentinfo"; 137 | key1 = "sno"; 138 | } 139 | if (paneParent.getSelectedIndex() == 2) { 140 | tableName = "dormitory"; 141 | key1 = "dno"; 142 | } 143 | //可以随意建表,我只写了两个表 144 | int row = table.getSelectedRow(); 145 | if (row != -1) { 146 | String key2 = (String) tableModel.getValueAt(row, 0); 147 | int result = JOptionPane.showConfirmDialog(null, "确定要删除吗?", "请确认", JOptionPane.YES_NO_OPTION); 148 | if (result == JOptionPane.OK_OPTION) { 149 | String sql = "delete from " + tableName + " where " + key1 + "='" + key2+ "'"; 150 | int num = sq.delete(sql); 151 | if (num > 0) { 152 | tableModel.removeRow(row); 153 | } 154 | } 155 | } else { 156 | JOptionPane.showMessageDialog(null, "请选择要删除的行!", "提示:", JOptionPane.ERROR_MESSAGE); 157 | } 158 | } 159 | //保存 160 | if ((JButton) e.getSource() == buttonSave) { 161 | if (table.isEditing()) { 162 | table.getCellEditor().stopCellEditing(); 163 | } 164 | int result = JOptionPane.showConfirmDialog(null, "请确认数值已经更改,否则保存无效", "请确认", JOptionPane.YES_NO_OPTION); 165 | if (result == JOptionPane.OK_OPTION) { 166 | int row = table.getRowCount(); 167 | int column = table.getColumnCount(); 168 | String[][] valueRow = new String[row][column]; 169 | String[] sqlvalue = new String[row]; 170 | for (int i = 0; i < row; i++) { 171 | for (int j = 0; j < column; j++) { 172 | valueRow[i][j] = String.valueOf(table.getValueAt(i, j)); 173 | } 174 | } 175 | if (paneParent.getSelectedIndex() == 1) { 176 | for (int i = 0; i < row; i++) { 177 | String sql = "insert into studentinfo" + " values ('" + valueRow[i][0].toString() + "','" + valueRow[i][1].toString() + "','" + valueRow[i][2].toString() + "','" + valueRow[i][3].toString() + "','" + valueRow[i][4].toString() + "','" + valueRow[i][5].toString() + "')"; 178 | sqlvalue[i] = sql.toString(); 179 | } 180 | data = sq.Save(sqlvalue, "studentinfo", row, column); 181 | tableModel.setDataVector(data, dataTitle); 182 | } 183 | if (paneParent.getSelectedIndex() == 2) { 184 | for (int i = 0; i < row; i++) { 185 | String sql = "insert into dormitory" + " values ('" + valueRow[i][0].toString() + "','" + valueRow[i][1].toString() + "')"; 186 | sqlvalue[i] = sql.toString(); 187 | } 188 | data = sq.Save(sqlvalue, "dormitory", row, column); 189 | tableModel.setDataVector(data, TitleDormitor); 190 | } 191 | } 192 | } 193 | //增加 194 | if ((JButton) e.getSource() == buttonIncrease) { 195 | tableModel.addRow(new Vector<>()); 196 | } 197 | } 198 | } 199 | --------------------------------------------------------------------------------