(The use of MySQL in the actual development of MIS information management system to end the reservation
development set
ID, name, age are public information, while students have results and workers have pay
Define an abstract class Person (ID, name, age), students are its subclasses, have achievements, and workers are its subclasses and have pay
How is ID defined?
It is best to generate the ID yourself. The best way is to use the following encoding method:
·Symbol time stamp three-digit random number
·Example: March 2009 2220:10:10.345
The symbol for students is s and the symbol for workers is w
· Generated ID number: student --gt;s20090322201010345023
worker --gt;w20090322201010345023
Since today's programs have to satisfy the operating specifications of files and databases, a common specification - interface should be defined here
When querying information, the sorting operation can be performed, and the Comparable interface can be used to terminate.
Operations involving the data layer throughout the code
· The data layer refers to the actual data operations -- gt; CRUD.
· The final result must be operated by one person (human workers and students)
There should be separation, one is comprehensive student management and the other is comprehensive worker management.
After the data layer operation specification defines the termination, there are two options. One is to directly use the subclass termination, but the future repair is not very convenient.
Therefore, it is best to use the idea of ??proxy design to end and be an intermediate layer.
Code Contact:
Main--gt;Menu--gt<imgsrc="titter.gif"smilieid="9"border="0"alt=""/>ersonOperate--gt;DAO
Since the program requests both file retention and database retention, a factory can be designed here, and the DAO operation subclass instance can be obtained through this factory.
On the basis of the previous program, the database function is added, and now it does not use the file retention, but uses the database for retention.
If a complete PersonDAO interface is divided into two interfaces, StudentDAO and WorkerDAO, the calling application does not have to fix the code.
The database uses mysql, so you need to install a separate database driver
##################Michael dividing line##########################
PersonDAO.java
packageorg.michael.demo.dao;
importjava.util.Set;
importorg.michael.demo.vo.Person;
//define the operation method of the detailed data
publicinterfacePersonDAO{
/
Operations that penetrate data
@paramperson
A person's information was stabbed
@return operation success or not
@throwsException
If there is an error, throw the error to the calling application management
/
publicbooleandoCreate(Personperson) throwsException;
/
update data operation
@paramperson
updated details
@return update success or not
@throwsException
If there is an error, throw the error
/
publicbooleandoUpdate(Personperson) throwsException;
/
Delete information by id
@paramid
Person's number
@return to delete or not
@throwsException
If there is an error, call the application management
/
publicbooleandoDelete(Stringid) throwsException;
/
Since the query is multiple, it is necessary to return the Set collection
@return comprehensive query results, a Set includes multiple Person targets
@throwsException
/
publicSetlt<imgsrc="titter.gif"smilieid="9"border="0"alt=""/>ersongt;findAll() throwsException;
/
query by id
@paramid
Person's number
@return detailed personnel information
@throwsException
/
publicPersonfindById(Stringid) throwsException;
/
Search by keyword
@paramkeyWord
Entered keywords
@return returns a set of information
@throwsException
/
publicSetlt<imgsrc="titter.gif"smilieid="9"border="0"alt=""/>ersongt;findByLike(StringkeyWord)throwsException;
}
PersonDAOImplJDBC.java
packageorg.michael.demo.dao.impl;
importjava.sql.PreparedStatement;
importjava.sql.ResultSet;
importjava.util.Set;
importjava.util.TreeSet;
importorg.michael.demo.dao.PersonDAO;
importorg.michael.demo.dbc.DataBaseConnection;
importorg.michael.demo.vo.Person;
importorg.michael.demo.vo.Student;
importorg.michael.demo.vo.Worker;
publicclassPersonDAOImplJDBCimplementsPersonDAO{
privateDataBaseConnectiondbc=null;
privateStringtype=null;
//The query operation is divided into two points, either querying workers or querying students
publicPersonDAOImplJDBC(Stringtype){
this();
this.type=type;
}
publicPersonDAOImplJDBC(){
}
publicbooleandoCreate(Personperson) throwsException{
this.dbc=newDataBaseConnection();
booleanflag=false;
try{
PreparedStatementpstmt=null;
//If a student is passed in, the type is 0, and if a worker is passed in, the type is 1
Stringsql=null;
floattemp=0.0f;
if(personinstanceofStudent){
Studentstu=(Student)person;
temp=stu.getScore();
sql=INSERTINTOtperson(id,name,age,score,type)VALUES(?,?,?,?,0);
}
if(personinstanceofWorker){
Workerwor=(Worker)person;
temp=wor.getSalary();
sql=INSERTINTOtperson(id,name,age,salary,type)VALUES(?,?,?,?,1);
}
pstmt=this.dbc.getConnection().pre
[Zero Basic Learning JAVA] JavaSE Practical Development-37.MIS Information Management System Practical Development [JDBC].doc)