This tutorial shares the specific java code of the student registration management system for your reference. The specific content is as follows
1. Requirement analysis
1.1 System Functional Design
(1) Be able to query students' basic information, such as: student number, name, age, class and gender (2) Be able to increase, delete, search, modify student information in the table and other functions (3) Be able to save data to MySQL database and record it (4) Be able to update data through mysql database
1.2 System module design
The academic record management system includes adding information modules, deleting information modules, modifying information modules, querying information modules, and updating data modules. System administrators can check students' student number, name, gender, age, awards and other information.
(For specific system structure design ER diagrams, please refer to Appendix 2)
2. System implementation
This system uses Java/JDBC language programming method to realize student status management.
Implementing mysql database with Java, this technology mainly uses the import of JDBC.jar, so that Java programmers can freely call standard database access classes and interfaces.
The combination of JDBC and Java allows users to easily implement most of the database operations using SQL statements. Java's easy portability is suitable for the characteristics of multiple operating systems and can meet user needs with JDBC.
2.1 Main layout files
According to the "principle of one thing, one place", the program is laid out and relevant documents are written for users to read. The data in mysql can also be exported to the "studinfo.txt" file for easy printing or reference by users. The JDBC used is version 5.0.8. 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 { Class.forName("com.mysql.jdbc.Driver"); // Establish a Connection connection with the database// The database is located in ip:127.0.0.1 (native) // The database port number: 3306 (mysql dedicated port number) // Database name studinfo // Encoding method UTF-8 // Account root // Password admin Connection c = DriverManager .getConnection( "jdbc:mysql://127.0.0.1:3306/studinfo?characterEncoding=UTF-8", "root", "admin"); System.out.println("Connection is successful, get the connection object: " + c); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } }}2.2 DAO interface
package jdbc;import java.util.List;import character.student;public interface DAO{ //Add public void add(student stud); //Modify public void update(student stud); //Delete public void delete(int id); //Get public Hero get(int id); //Query public List<student> list(); //Page query public List<student> list(int start, int count);}// Please check the appendix comments on the page after the detailed SQL statements and code implementations!
2.3 Design method
The single-instant design model is adopted. When designing the functions of adding, deleting, searching and modifying, the database is called independently to avoid the hassle of maintaining the software in the later stage. This software will independently take out the connection database function as a class. It only needs to be called when used later, without repeatedly implementing large segments of database connection code, reducing code redundancy, which is conducive to further improvement of the later system and facilitates reading by other programmers.
(The following is to facilitate the teacher's reading, only singleton display of SQL-conncet connections is done!)
package util;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;public class DBUtil { static String ip = "127.0.0.1"; static int port = 3306; static String database = "student"; static String encoding = "UTF-8"; static String loginName = "root"; static String password = "admin"; static{ try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } } 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
Use buttons to implement the addition, deletion, modification and import functions at the bottom of the interface. You can type the student ID in the box below to implement the query function (here, assuming that the id is the only primary key of the system, just trigger Enter)
3. System defects
There are many bugs 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 inserting the new student number, it may cause conflicts with the old student number, resulting in the automatic shutdown of the software. Overall, there are still many improvements, and we hope to repair it further.
Secondly, the software designed this time has only one student, which is relatively single, so it is not too troublesome to implement. There is just that there is no room for the implementation of the ER diagrams and other designs learned in class to be investigated. I hope that during the winter vacation, the query between students, courses, and teachers can be realized, and this system can be further improved.
4. Pros and cons of file system implementation and database implementation
The file system is aimed at a certain application, with poor sharing, high redundancy, poor data independence, and a structure in the record, and an overall structure without the structure, which is controlled by the application itself.
The database system is oriented towards the real world, has high sharing, low redundancy, has high physical independence and certain logical uniqueness, and is structured overall and described by the data model. The database management system provides data security, integrity, concurrent control and recovery capabilities. Improve data sharing; reduce data redundancy and improve data consistency; adopt certain data models to realize data structure; data is managed and controlled by DBMS, and is more conducive to the operation and use of non-computer people, reducing learning costs. And with the development of database technology and the use of today's software, users are not aware of their software's use of database functions.
Appendix 1: SQL statements in code snippets are added, deleted, and delete (the implementation of functions is relatively the same. Here, the first update, add, delete function is displayed, and the cumbersome code is not repeatedly displayed, and only the key code is listed for reference)
1. Updated implementation
// update Implementation code snippet 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) { se.printStackTrace(); } finally { destroy(); } return result; }2. Delete implementation code ( the format and class establishment are the same as 1, just change the 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 based on 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 (rs.next()) { result = 1; } return result; } }For more learning materials, please pay attention to the special topic "Management System Development".
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.