Realization of University Student Dormitory Management System by Database System

Table of contents

Table of contents

Chapter One Introduction

1.1 Background of the project research

Chapter Two Feasibility Analysis and Demand Analysis

2.1 Feasibility analysis

2.1.1 Operation Feasibility

2.1.2 Technical Feasibility

2.1.3 Design Feasibility

2.2 Demand Analysis

2.2.1 Processing object analysis

2.2.2 Analysis of Functional Requirements

2.2.3 Security and Integrity Analysis

Chapter 3 System Design

3.1 System Architecture Diagram

3.2 ER Diagram

3.3 Data structure

3.3.1 User Information Structure

3.3.2 Student Information Structure

3.3.3 Dormitory information structure

3.3.4 Absence information structure

3.4 Data Dictionary

3.4.1 Data dictionary for dormitory students (table name: student)

3.4.2 Dormitory data dictionary (table name: drom)

3.4.3 Dormitory administrator data dictionary (table name: dormmanager)

3.4.4 User data dictionary (table name: record)

3.5 Database design

Chapter 4 System Implementation and Design Content

4.1 System logic design and implementation

4.2 Function of connecting to database

4.3 Functional modules

Chapter 5 System Implementation

5.1 Page display effect

5.1.1 Login interface

Chapter 6 Testing and Deployment

6.1 Operating environment

6.2 System Test

Appendix Core Code Implementation

Chapter One Introduction

1.1 Background of the project research

The student dormitory management system is an essential part of a school. At present, many schools are still in the initial stage of manually recording data by dormitory managers. Manual recording is barely acceptable for small-scale schools, but for colleges and universities with a large amount of student information and a large amount of data that needs to be recorded and archived, Manual recording is quite cumbersome. And when looking for a certain record, due to the huge amount of data, you can only search one by one manually, which is not only troublesome but also wastes a lot of time, and the efficiency is relatively low. Today's society is a world of rapid progress, the original recording method has been eliminated by the society, and computerized management is the product of adapting to the times. The information world will never be a peaceful world. When a technology cannot meet the demand, a new technology will be born to replace the old technology. Today in the 21st century, The information society occupies a mainstream position, the use of computers in all walks of life has been popularized, and automation and information management are more and more widely used in various fields. We have designed a set of student dormitory management system for this. The student dormitory management system adopts computerized management. The system is as humanized as possible. Users will feel that the operation is very convenient. All the administrators need to do is to input the data into the system database. Since the database storage capacity is quite large and relatively stable, it is suitable for long-term storage and is not easy to lose. This undoubtedly provides a convenient and fast operation method for schools with a relatively large amount of information storage. This system has the advantages of fast running speed, high security and good stability, and has perfect report generation and modification functions, and can quickly query the accommodation information required by the school. Student dormitory is an important space environment for college students to study, live and communicate on campus. College students spend about 2/3 of their time in the dormitory environment. With the expansion of the scale of colleges and universities, the academic level, ideological state and cultural level of the students in the school are diversified and complicated, which has brought many new problems to the student management work to a large extent. With the increase in the number of students, the amount of information in the management of student dormitories in colleges and universities is increasing. At present, the management of student dormitories in our school still adopts the traditional working method-the book-based working mode. This mode is slow to obtain information, difficult to consult, and poor in accuracy. , it is difficult to adapt to the needs of high-level dormitory management, and at the same time it brings a lot of waste of manpower, which brings a lot of inconvenience to the work of dormitory management. Based on this, we thought of the need to develop a "student dormitory management system" to improve the management efficiency of the dormitory, improve the management method, and make it in line with the trend of modern informationization. Since the storage capacity of the database is quite large and relatively stable, it is suitable for long-term storage and is not easy to lose. This undoubtedly provides a convenient and fast operation method for schools with a relatively large amount of information storage.

1.2 Project selection and purpose significance

The user who chooses the student dormitory management system as the topic will feel that the operation is very convenient. All the administrators need to do is to input the data into the system database. Since the database storage capacity is quite large and relatively stable, it is suitable for long-term storage and is not easy to lose. This undoubtedly provides a convenient and fast operation method for schools with a relatively large amount of information storage. This system has the advantages of fast running speed, high security and good stability, and has perfect report generation and modification functions, which can quickly query the accommodation information required by the school, and facilitate the management of student dormitories by colleges and universities.

1.3 Objectives and Requirements of Project Research

Overall goal: to successfully develop a student dormitory management system. Realize functions such as querying, adding, and deleting student dormitory information, which is convenient for management and saves manpower.

Tasks and requirements: be able to operate the dormitory management system to achieve the purpose of management. Requirements: Beautiful interface, complete functions such as adding, deleting, and querying.

Chapter Two Feasibility Analysis and Demand Analysis

2.1 Feasibility analysis

2.1.1 Operation Feasibility

The operating system used in this system is windows10, which is relatively simple to operate for people who have entered the Internet age, and it is feasible in terms of operation.

2.1.2 Technical Feasibility

This system is developed by combining technologies such as spring + springmvc, and it is technically feasible. For the development of the interface, the currently popular framework Bootstrap is used, which is very friendly in terms of interaction and easy to operate and develop. In terms of database, mysql is used, which is guaranteed in terms of security, and mysql is more portable.

2.1.3 Design Feasibility

The design of this system adopts the MVC model, which can well divide the page display, business logic processing, and data access. The coupling between each level is low, which greatly improves the flexibility of the project and the overall division of the system. It is relatively clear, so it is also feasible in terms of design.

2.2 Demand Analysis

The student dormitory management system is an essential part of a school. At present, many schools are still in the initial stage of manually recording data by dormitory managers. Manual recording is barely acceptable for small-scale schools, but for colleges and universities with a large amount of student information and a large amount of data that needs to be recorded and archived, Manual recording is quite cumbersome. And when looking for a certain record, due to the huge amount of data, you can only search one by one manually, which is not only troublesome but also wastes a lot of time, and the efficiency is relatively low. Today's society is a world of rapid progress, the original recording method has been eliminated by the society, and computerized management is the product of adapting to the times. The information world will never be a peaceful world. When a technology cannot meet the demand, a new technology will be born to replace the old technology. Today in the 21st century, the information society occupies a mainstream position, the use of computers in all walks of life has been popularized, and automation and information management are more and more widely used in various fields. We have designed a set of student dormitory management system for this.

2.2.1 Processing object analysis

The objects to be processed by the system include basic information of students, basic information of dormitories, basic information of dormitory buildings, basic information of building administrators, and basic information of visitors. The information of each object is as follows:

1. Student basic information (Student): including student number, student name, student gender, student check-in and move-out, student age and student phone number, etc., which can facilitate the query and update of student information;

2. Basic information of dormitory students (Dormitory): including student number, student name, building number, dormitory room, dormitory contact number;

3. Dormitory basic information (Building): including dormitory building number, dormitory building gender classification information, administrator name, etc., which can facilitate the management of the dormitory building and improve query efficiency;

4. Basic information of building administrators (Teacher): including staff number, staff name, gender, work dormitory, and telephone, which can facilitate the appointment, information query and modification of dormitory managers by managers;

2.2.2 Analysis of Functional Requirements

The system mainly completes the following functions:

1. Query and modify the basic information of the dormitory building;

2. Query, update and insert basic information of students;

3. Inquiry and update of dormitory information in each dormitory building;

(1) The dormitory information management system realizes the reading of all the information of students and administrators; realizes the reading of specific information of a student or administrator;

(2) Realize the deletion of a person's information;

4. Check-in and move-out records of occupants in the dormitory building;

2.2.3 Security and Integrity Analysis

Security first passes through the view mechanism, different users can only access the views authorized by the system, which can provide a certain degree of security for system data, and then through the user authorization mechanism, the user is required to log in to identify the user level, and assign users according to this level Permissions to achieve a higher level of data security and confidentiality functions.

Integrity requirements are used to describe the basic information of the dormitory building, the basic information of the students, the basic information of the dormitory, the basic information of the building administrator, and some user-defined integrity (in line with actual requirements)

Chapter 3 System Design

3.1 System Architecture Diagram

3.2 ER Diagram

ER into relational model

Building manager: dormmanager ( uresname , password, stuName, sex)

Dorm management: dorm( dormName , dormType, dormNumber, dormTel)

Student: student( stuName ,stuNum,dormBuild,dormName,sex)

3.3 Data structure

3.3.1 User Information Structure

3.3.2 Student Information Structure

3.3.3 Dormitory information structure

3.3.4 Absence information structure

3.4 Data Dictionary

3.4.1 Data dictionary for dormitory students (table name: student)

attribute name

field name

type

length

constraint

student number

stuNum

Varchar

20

primary key

password

password

Varchar

20

Not Null

Name

name

Varchar

20

Not Null

gender

sex

Varchar

4

Not Null

Dormitory building number

dormBuildId

Int

6

Not Null

check-in number

stuNum

Varchar

20

Not Null

dormitory number

dormName

Varchar

20

Not Null

Contact information

tel

Varchar

20

Not Null

3.4.2 Dormitory data dictionary (table name: drom)

attribute name

field name

type

length

constraint

dormitory number

Bottom

Varchar2

6

primary key

dormitory

Dbuild

Varchar2

10

Not Null

3.4.3 Dormitory administrator data dictionary (table name: dormmanager)

attribute name

field name

type

length

constraint

host username

userName

Varchar

20

primary key

login password

password

Varchar

20

Not Null

Residence Management Building No.

dormBuildId

int

4

Not Null

student name

name

Varchar

6

Not Null

gender

sex

Varchar

20

Not Null

Contact information

tel

Varchar

20

Not Null

3.4.4 User data dictionary (table name: record)

attribute name

field name

type

length

constraint

Absent Student Number

studentNumber

Varchar

20

primary key

Absent Student Name

studentName

Varchar

30

Not Null

Dormitory building number

dormBuildId

Int

4

Not Null

dormitory number

dormName

Varchar

6

Not Null

date

date

Dat

20

Not Null

缺勤情况

detail

Varchar

20

Not Null

3.5 数据库的设计

(1)系统管理员表

(2)宿舍管理表

(3)宿舍管理表

(4)学生管理表

(5)宿舍管理员表

(6)缺勤记录表

第四章 系统实现与设计内容

4.1系统逻辑设计与实现

4.2连接数据库功能

public class JDBCUtil {
    //获取数据库连接的方法
    public Connection getConn(){
        Connection conn=null;
        try {
            Class.forName(PropertiesUtil.getValue("jdbcName"));
            conn= DriverManager.getConnection(PropertiesUtil.getValue("dbUrl"), PropertiesUtil.getValue("dbUserName"), PropertiesUtil.getValue("dbPassword"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  conn;
    }
    //关闭数据库连接、关闭执行对象、关闭结果集对象(关闭资源)
    public void closeAll(ResultSet rs, Statement st,Connection conn){
        if(rs!=null){
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(st!=null){
            try {
                st.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(conn!=null){
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
}

4.3 功能模块

登陆方式:系统管理员,宿舍管理员,学生

<1> 系统管理员

(1)后台首页显示

(2)宿舍管理员管理:可查询,添加和删除宿舍管理员,宿舍管理员的信息进行修改

(3)学生管理:可对学生进行入住登记,迁出,对学生信息进行查询,修改和删除

(4)宿舍楼管理:可添加宿舍,为宿舍分配宿舍管理员,对分配的宿舍管理员进行修改

(5)学生缺寝记录:记录学生的缺寝情况

(6)修改密码

(7)退出系统

<2> 宿舍管理员

(1)后台首页显示

(2)学生查看

(3)学生缺寝记录:由宿舍管理员登记学生缺寝情况

(4)修改密码

(5)退出系统

<3> 学生

(1)后台首页显示

(2)我的缺勤记录:查看缺寝情况

(3)修改密码

(4)退出系统

第五章 系统实现

5.1页面显示效果

5.1.1登录界面

有三种登录可选择: 1.系统管理员 2.宿舍管理员 3.学生。

(1) 主页面

第六章 测试与部署

6.1 运行环境

Jdk15 IDEA tomcat8.5 mysql Navicat Premium

6.2 系统测试

登录功能测试

系统管理员界面功能测试

(1)宿舍楼管理(首页+添加宿舍楼+添加成功显示页面)

(3)宿舍楼层管理(宿舍楼管理主界面+添加宿舍楼界面+添加成功显示界面)

附录核心代码实现

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="com.lero.model.Admin" %>
<%@ page import="com.lero.model.DormManager" %>
<%@ page import="com.lero.model.Student" %>
<%
   if(request.getAttribute("user")==null){
      String userName=null;
      String password=null;
      String userType=null;
      String remember=null;
      
      Cookie[] cookies=request.getCookies();
      for(int i=0;cookies!=null && i<cookies.length;i++){
         if(cookies[i].getName().equals("dormuser")){
            userName=cookies[i].getValue().split("-")[0];
            password=cookies[i].getValue().split("-")[1];
            userType=cookies[i].getValue().split("-")[2];
            remember=cookies[i].getValue().split("-")[3];
         }
      }
      
      if(userName==null){
         userName="";
      }
      
      if(password==null){
         password="";
      }
      
      if(userType==null){
         userType="";
      } else if("admin".equals(userType)){
         pageContext.setAttribute("user", new Admin(userName,password));
         pageContext.setAttribute("userType", 1);
      } else if("dormManager".equals(userType)) {
         pageContext.setAttribute("user", new DormManager(userName,password));
         pageContext.setAttribute("userType", 2);
      } else if("student".equals(userType)) {
         pageContext.setAttribute("user", new Student(userName,password));
         pageContext.setAttribute("userType", 3);
      }
      
      if("yes".equals(remember)) {
         pageContext.setAttribute("remember", 1);
      }
      
   }
%>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>宿舍管理系统登录</title>
<link href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/bootstrap/js/jQuery.js"></script>
<script src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript">
   function checkForm() {
      var userName = document.getElementById("userName").value;
      var password = document.getElementById("password").value;
      var userTypes = document.getElementsByName("userType");
      var userType = null;
      for(var i=0;i<userTypes.length;i++) {
         if(userTypes[i].checked) {
            userType=userTypes[i].value;
            break;
         }
      }
      if (userName == null || userName == "") {
         document.getElementById("error").innerHTML = "用户名不能为空";
         return false;
      }
      if (password == null || password == "") {
         document.getElementById("error").innerHTML = "密码不能为空";
         return false;
      }
      if (userType == null || userType == "") {
         document.getElementById("error").innerHTML = "请选择用户类型";
         return false;
      }
      return true;
   }
</script>

<style type="text/css">
     body {
        padding-top: 200px;
        padding-bottom: 40px;
        background-image: url('images/单车男孩背影是骑士2.jpg');
        background-position: center;
      background-attachment: fixed;
      }
      
      .radio {
       padding-top: 10px;
           padding-bottom:10px;
      }
      
      .form-signin-heading{
       text-align: center;
      }

      .form-signin {
        max-width: 300px;
        padding: 19px 29px 0px;
        margin: 0 auto 20px;
        background-color: #fff;
        border: 1px solid #e5e5e5;
        -webkit-border-radius: 5px;
           -moz-border-radius: 5px;
                border-radius: 5px;
        -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
           -moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
                box-shadow: 0 1px 2px rgba(0,0,0,.05);
      }
      .form-signin .form-signin-heading,
      .form-signin .checkbox {
        margin-bottom: 10px;
      }
      .form-signin input[type="text"],
      .form-signin input[type="password"] {
        font-size: 16px;
        height: auto;
        margin-bottom: 15px;
        padding: 7px 9px;
      }
</style>

</head>
<body>
<div class="container">
      <form name="myForm" class="form-signin" action="login" method="post" onsubmit="return checkForm()">
        <h2 class="form-signin-heading"><font color="gray">宿舍管理系统</font></h2>
        <input id="userName" name="userName" value="${user.userName }" type="text" class="input-block-level" placeholder="用户名...">
        <input id="password" name="password" value="${user.password }" type="password" class="input-block-level" placeholder="密码..." >
        <label class="radio inline">
          <input id="admin" type="radio" name="userType" value="admin"  checked/> 系统管理员
      </label>
      <label class="radio inline">
         <input id="dormManager" type="radio" name="userType" value="dormManager" ${userType==2?'checked':''} /> 宿舍管理员
      </label>
      <label class="radio inline">
         <input id="student" type="radio" name="userType" value="student"  ${userType==3?'checked':''}/> 学生
      </label>
        <label class="checkbox">
          <input id="remember" name="remember" type="checkbox" value="remember-me" ${remember==1?'checked':''}>记住我     <font id="error" color="red">${error }</font>  
        </label>
        <button class="btn btn-large btn-primary" type="submit">登录</button>
            
        <button class="btn btn-large btn-primary" type="button" >重置</button>

      </form>
</div>
</body>
</html>


package com.lero.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.lero.model.DormBuild;
import com.lero.model.Student;
import com.lero.util.StringTool;

public class StudentDao {

// public List<Student> studentList(Connection con, PageBean pageBean, Student s_student)throws Exception {
//    List<Student> studentList = new ArrayList<Student>();
//    StringBuffer sb = new StringBuffer("select * from t_student t1");
//    if(StringUtil.isNotEmpty(s_student.getName())) {
//       sb.append(" and t1.name like '%"+s_student.getName()+"%'");
//    } else if(StringUtil.isNotEmpty(s_student.getStuNumber())) {
//       sb.append(" and t1.stuNum like '%"+s_student.getStuNumber()+"%'");
//    } else if(StringUtil.isNotEmpty(s_student.getDormName())) {
//       sb.append(" and t1.dormName like '%"+s_student.getDormName()+"%'");
//    }
//    if(s_student.getDormBuildId()!=0) {
//       sb.append(" and t1.dormBuildId="+s_student.getDormBuildId());
//    }
//    if(pageBean != null) {
//       sb.append(" limit "+pageBean.getStart()+","+pageBean.getPageSize());
//    }
//    PreparedStatement pstmt = con.prepareStatement(sb.toString().replaceFirst("and", "where"));
//    ResultSet rs = pstmt.executeQuery();
//    while(rs.next()) {
//       Student student=new Student();
//       student.setStudentId(rs.getInt("studentId"));
//       int dormBuildId = rs.getInt("dormBuildId");
//       student.setDormBuildId(dormBuildId);
//       student.setDormBuildName(DormBuildDao.dormBuildName(con, dormBuildId));
//       student.setDormName(rs.getString("dormName"));
//       student.setName(rs.getString("name"));
//       student.setSex(rs.getString("sex"));
//       student.setStuNumber(rs.getString("stuNum"));
//       student.setTel(rs.getString("tel"));
//       student.setPassword(rs.getString("password"));
//       studentList.add(student);
//    }
//    return studentList;
// }
   
   public List<Student> studentList(Connection con, Student s_student)throws Exception {
      List<Student> studentList = new ArrayList<Student>();
      StringBuffer sb = new StringBuffer("select * from t_student t1");
      if(StringTool.isNotEmpty(s_student.getName())) {
         sb.append(" and t1.name like '%"+s_student.getName()+"%'");
      } else if(StringTool.isNotEmpty(s_student.getStuNumber())) {
         sb.append(" and t1.stuNum like '%"+s_student.getStuNumber()+"%'");
      } else if(StringTool.isNotEmpty(s_student.getDormName())) {
         sb.append(" and t1.dormName like '%"+s_student.getDormName()+"%'");
      }
      if(s_student.getDormBuildId()!=0) {
         sb.append(" and t1.dormBuildId="+s_student.getDormBuildId());
      }
      PreparedStatement pstmt = con.prepareStatement(sb.toString().replaceFirst("and", "where"));
      ResultSet rs = pstmt.executeQuery();
      while(rs.next()) {
         Student student=new Student();
         student.setStudentId(rs.getInt("studentId"));
         int dormBuildId = rs.getInt("dormBuildId");
         student.setDormBuildId(dormBuildId);
         student.setDormBuildName(DormBuildDao.dormBuildName(con, dormBuildId));
         student.setDormName(rs.getString("dormName"));
         student.setName(rs.getString("name"));
         student.setSex(rs.getString("sex"));
         student.setStuNumber(rs.getString("stuNum"));
         student.setTel(rs.getString("tel"));
         student.setPassword(rs.getString("password"));
         studentList.add(student);
      }
      return studentList;
   }
   
   public static Student getNameById(Connection con, String studentNumber, int dormBuildId)throws Exception {
      String sql = "select * from t_student t1 where t1.stuNum=? and t1.dormBuildId=?";
      PreparedStatement pstmt=con.prepareStatement(sql);
      pstmt.setString(1, studentNumber);
      pstmt.setInt(2, dormBuildId);
      ResultSet rs=pstmt.executeQuery();
      Student student = new Student();
      if(rs.next()) {
         student.setName(rs.getString("name"));
         student.setDormBuildId(rs.getInt("dormBuildId"));
         student.setDormName(rs.getString("dormName"));
      }
      return student;
   }
   
   public boolean haveNameByNumber(Connection con, String studentNumber)throws Exception {
      String sql = "select * from t_student t1 where t1.stuNum=?";
      PreparedStatement pstmt=con.prepareStatement(sql);
      pstmt.setString(1, studentNumber);
      ResultSet rs=pstmt.executeQuery();
      Student student = new Student();
      if(rs.next()) {
         student.setName(rs.getString("name"));
         student.setDormBuildId(rs.getInt("dormBuildId"));
         student.setDormName(rs.getString("dormName"));
         return true;
      }
      return false;
   }
   
   public List<Student> studentListWithBuild(Connection con, Student s_student, int buildId)throws Exception {
      List<Student> studentList = new ArrayList<Student>();
      StringBuffer sb = new StringBuffer("select * from t_student t1");
      if(StringTool.isNotEmpty(s_student.getName())) {
         sb.append(" and t1.name like '%"+s_student.getName()+"%'");
      } else if(StringTool.isNotEmpty(s_student.getStuNumber())) {
         sb.append(" and t1.stuNum like '%"+s_student.getStuNumber()+"%'");
      } else if(StringTool.isNotEmpty(s_student.getDormName())) {
         sb.append(" and t1.dormName like '%"+s_student.getDormName()+"%'");
      }
      sb.append(" and t1.dormBuildId="+buildId);
      PreparedStatement pstmt = con.prepareStatement(sb.toString().replaceFirst("and", "where"));
      ResultSet rs = pstmt.executeQuery();
      while(rs.next()) {
         Student student=new Student();
         student.setStudentId(rs.getInt("studentId"));
         int dormBuildId = rs.getInt("dormBuildId");
         student.setDormBuildId(dormBuildId);
         student.setDormBuildName(DormBuildDao.dormBuildName(con, dormBuildId));
         student.setDormName(rs.getString("dormName"));
         student.setName(rs.getString("name"));
         student.setSex(rs.getString("sex"));
         student.setStuNumber(rs.getString("stuNum"));
         student.setTel(rs.getString("tel"));
         student.setPassword(rs.getString("password"));
         studentList.add(student);
      }
      return studentList;
   }
   
   public List<DormBuild> dormBuildList(Connection con)throws Exception {
      List<DormBuild> dormBuildList = new ArrayList<DormBuild>();
      String sql = "select * from t_dormBuild";
      PreparedStatement pstmt = con.prepareStatement(sql);
      ResultSet rs = pstmt.executeQuery();
      while(rs.next()) {
         DormBuild dormBuild=new DormBuild();
         dormBuild.setDormBuildId(rs.getInt("dormBuildId"));
         dormBuild.setDormBuildName(rs.getString("dormBuildName"));
         dormBuild.setDetail(rs.getString("dormBuildDetail"));
         dormBuildList.add(dormBuild);
      }
      return dormBuildList;
   }
   
   public int studentCount(Connection con, Student s_student)throws Exception {
      StringBuffer sb = new StringBuffer("select count(*) as total from t_student t1");
      if(StringTool.isNotEmpty(s_student.getName())) {
         sb.append(" and t1.name like '%"+s_student.getName()+"%'");
      } else if(StringTool.isNotEmpty(s_student.getStuNumber())) {
         sb.append(" and t1.stuNum like '%"+s_student.getStuNumber()+"%'");
      } else if(StringTool.isNotEmpty(s_student.getDormName())) {
         sb.append(" and t1.dormName like '%"+s_student.getDormName()+"%'");
      }
      if(s_student.getDormBuildId()!=0) {
         sb.append(" and t1.dormBuildId="+s_student.getDormBuildId());
      }
      PreparedStatement pstmt = con.prepareStatement(sb.toString().replaceFirst("and", "where"));
      ResultSet rs = pstmt.executeQuery();
      if(rs.next()) {
         return rs.getInt("total");
      } else {
         return 0;
      }
   }
   
   public Student studentShow(Connection con, String studentId)throws Exception {
      String sql = "select * from t_student t1 where t1.studentId=?";
      PreparedStatement pstmt=con.prepareStatement(sql);
      pstmt.setString(1, studentId);
      ResultSet rs=pstmt.executeQuery();
      Student student = new Student();
      if(rs.next()) {
         student.setStudentId(rs.getInt("studentId"));
         int dormBuildId = rs.getInt("dormBuildId");
         student.setDormBuildId(dormBuildId);
         student.setDormBuildName(DormBuildDao.dormBuildName(con, dormBuildId));
         student.setDormName(rs.getString("dormName"));
         student.setName(rs.getString("name"));
         student.setSex(rs.getString("sex"));
         student.setStuNumber(rs.getString("stuNum"));
         student.setTel(rs.getString("tel"));
         student.setPassword(rs.getString("password"));
      }
      return student;
   }
   
   public int studentAdd(Connection con, Student student)throws Exception {
      String sql = "insert into t_student values(null,?,?,?,?,?,?,?)";
      PreparedStatement pstmt=con.prepareStatement(sql);
      pstmt.setString(1, student.getStuNumber());
      pstmt.setString(2, student.getPassword());
      pstmt.setString(3, student.getName());
      pstmt.setInt(4, student.getDormBuildId());
      pstmt.setString(5, student.getDormName());
      pstmt.setString(6, student.getSex());
      pstmt.setString(7, student.getTel());
      return pstmt.executeUpdate();
   }
   
   public int studentDelete(Connection con, String studentId)throws Exception {
      String sql = "delete from t_student where studentId=?";
      PreparedStatement pstmt=con.prepareStatement(sql);
      pstmt.setString(1, studentId);
      return pstmt.executeUpdate();
   }
   
   public int studentUpdate(Connection con, Student student)throws Exception {
      String sql = "update t_student set stuNum=?,password=?,name=?,dormBuildId=?,dormName=?,sex=?,tel=? where studentId=?";
      PreparedStatement pstmt=con.prepareStatement(sql);
      pstmt.setString(1, student.getStuNumber());
      pstmt.setString(2, student.getPassword());
      pstmt.setString(3, student.getName());
      pstmt.setInt(4, student.getDormBuildId());
      pstmt.setString(5, student.getDormName());
      pstmt.setString(6, student.getSex());
      pstmt.setString(7, student.getTel());
      pstmt.setInt(8, student.getStudentId());
      return pstmt.executeUpdate();
   }
   
   
}


源码以及数据库文件获取

请到我的主页中心下载 都是大学生 大家互帮互助 现在是免费的呢 感谢大家的支持!

Guess you like

Origin blog.csdn.net/weixin_53251411/article/details/128984093