java implements the school roll management system

  • 2020-05-27 04:47:02
  • OfStack

This tutorial for you to share the specific java code of the school management system, for your reference, the specific content is as follows

1. Demand analysis

1.1 system function design

(1) be able to query students' basic information, such as student number, name, age, class and gender
(2) it can add, delete, search and modify the student information in the form
(3) data can be saved to MySQL database and recorded
(4) data can be updated through mysql database

1.2 system module design

The system includes adding information module, deleting information module, modifying information module, inquiring information module and updating data module. System administrator can query the student's student number, name, gender, age, awards and other information.
(please refer to appendix 2 for the detailed design of E-R)

2. System implementation

This system USES Java/JDBC language programming method to achieve the school roll management.
The mysql database is implemented with Java, which mainly USES the import JDBC.jar, enabling Java programmers to freely invoke standard database access classes and interfaces.
The combination of JDBC and Java makes it easy for users to use sql statements to realize most operations of the database, while Java is easy to transplant, suitable for a variety of operating systems and JDBC, which can meet the needs of users.

2.1 main layout files

According to the principle of "one thing one place", the layout of this program is carried out, and relevant documents are written for users to read. The data in mysql can also be exported to the file "studinfo.txt" for users to print or refer to. Version 5.0.8 of JDBC was adopted. 2.2 key interface segment code and its annotations

package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class TestJDBC {
 public static void main(String[] args) {

 try {

  //  Build with database Connection The connection 
  //  Where the database is located ip: ( This machine )
  //  The port number of the database:  3306  ( mysql Dedicated port number) 
  //  Database name  studinfo
  //  encoding  UTF-8
  //  account  root
  //  password  admin

  Connection c = DriverManager
    "root", "admin");

  System.out.println(" Connect successfully, get the connection object:  " + c);

 } catch (ClassNotFoundException e) {
 } catch (SQLException e)  { 


2.2 DAO interface

package jdbc;

import java.util.List;

import charactor.student;

public interface DAO{
 // increase 
 public void add(student stud);
 // Modify the 
 public void update(student stud);
 // delete 
 public void delete(int id);
 // To obtain 
 public Hero get(int id);
 // The query 
 public List<student> list();
 // Paging query 
 public List<student> list(int start, int count);

// for details of sql statement and code implementation, please refer to the appendix at the back page for remarks!

2.3 design method

Using singleton design pattern, in add and remove check change function design, respectively independently the invocation of the database, so as to avoid the late maintenance software, the software will connect to the database function separate out and as a class, you just need to call, when used in the later without implementation of database connection code repeatedly, reduce code redundancy, late for further perfecting the system, as well as for other programmers to read.

(for the convenience of teachers, only the singleton of sql-conncet connection is shown below!)

package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtil {
 static String ip = "";
 static int port = 3306;
 static String database = "student";
 static String encoding = "UTF-8";
 static String loginName = "root";
 static String password = "admin";
 try {
 } catch (ClassNotFoundException e) {

 public static Connection getConnection() throws SQLException {
 String url = String.format("jdbc:mysql://%s:%d/%s?characterEncoding=%s", ip, port, database, encoding);
 return DriverManager.getConnection(url, loginName, password);

2.4 interface display
At the bottom of the interface, add, delete, modify and import functions can be achieved through buttons. In the box below, you can type student id to realize the query function (here, it is assumed that id is the primary key of the system only 1, and press enter can be triggered).

3. System defects

There are a lot of bug in this system. For example, when importing and exporting data, the blank lines between the new data and the old data cannot be eliminated. When the new student number is inserted, it may cause conflicts with the old student number, resulting in the automatic shutdown of the software.
Second is that the design of the software entity only one student, a single 1, so to implement is not too much trouble, just don't have a lot of leeway to learn in the class E - R diagram design implementation to join, hope can realize students winter vacation, courses, and the query between teacher 3 tables, will further improve the system.

4. The pros and cons of file system implementation and database implementation

File system for a certain application, poor sharing, high redundancy, poor data independence, records with structure, the overall structure, by the application itself control.

Facing the real world, the database system has high sharing, small redundancy, high physical independence and logical independence. The overall structure is described by the data model. The database management system provides data security, integrity, concurrency control and recovery ability. Improved the sharing of data; The redundancy of data is reduced, and the 1-tropism of data is improved. 1 definite data model is used to realize data structure. The data is managed and controlled by DBMS system 1, which is more convenient for non-computer users to operate and use, thus reducing the learning cost. And with the development of database technology and the use of today's software, users are not aware that their software is using database functions.

Appendix 1: the sql statement in the code snippet implements the addition, deletion, lookup and modification
(the implementation of the functions is similar. The first update, add and delete functions shown here do not repeat the tedious code, but only list the key codes for reference.)

1. Implementation of update

// update  Implementation code snippets 

public update(Student stu) { 
 boolean result = false; 
 if (stu == null) { 
  return result; 
 try { 
  // check 
  if (queryBySno(stu.getSno()) == 0) { 
  return result; 
  //  implementation update
  String sql = "update student set id=?,name=?,class=?,sex=?"; 
  String[] param = { stu.getId(), stu.getName(), stu.getClass(), stu.getSex() }; 
  int rowCount = db.executeUpdate(sql, param); 
  if (rowCount == 1) { 
  result = true; 
 } catch (SQLException se) { 
 } finally { 
 return result; 

2.delete implementation code (the format and class creation are the same as 1, just change sql statement)

String sql = "delete from student where id =?" ; 
String[] param = { stu.getId()}; 

3.add implementation code

String sql = "insert into student(id . name . class . sex) values(?,?,?,?)"; 
String[] param = { stu.getId(), stu.getName(), stu.getClass(), stu.getSex()};  

4. Query implementation (query according to id)

private int queryById(String id) throws SQLException { 
 int result = 0; 
 if ("".equals(id) || id == null) { 
 return result; 
 String checkSql = "select * from student where id=?"; 
 String[] checkParam = { id }; 
 rs = db.executeQuery(checkSql, checkParam); 
 if ( { 
 result = 1; 
 return result; 


For more information, please refer to the topic "management system development".

Related articles: