找回密码
 立即注册
企业管理 2022-09-23 88 0star收藏 版权: . 保留作者信息 . 禁止商业使用 . 禁止修改作品
MIS信息管理系统实践开发之使用MySQL终结保留
开发布景
ID、名称、年纪为公共信息,而学生有成果,工人有薪酬
定义一个抽象类Person(ID、名称、年纪),学生是其子类,有成果,工人是其子类有薪酬
ID如何定义呢?
ID最好可以自己生成,最好的方法是选用下面的编码方法:
·符号+时刻戳+三位随机数
·例如:2009年3月2220:10:10.345
·学生的符号为s,工人的符号为w
·生成的ID号:学生--gt;s20090322201010345023
工人--gt;w20090322201010345023
由于如今的程序要满意文件和数据库的操作规范,所以此处应当定义出一个公共的规范——接口
查询信息的时候可以进行排序操作,可以使用Comparable接口终结。
整个代码中牵扯到数据层的操作
·数据层就是指实在的数据操作--gt;CRUD。
·终究成果操作的肯定是一个人(人为工人和学生)
应当进行分隔,一个是全面的学生管理,一个是全面的工人管理。
数据层操作规范定义终结今后,有两种选择,一种是直接使用子类终结,可是今后的修复不是很方便,
所以此处最好使用代/理设计的思路终结,做一个中间层。
代码联系:
Main--gt;Menu--gt<imgsrc="titter.gif"smilieid="9"border="0"alt=""/>ersonOperate--gt;DAO
由于程序即请求使用文件保留,又请求使用数据库保留,所以此处可以设计出一个工厂,通过此工厂进行DAO的操作子类实例获得。
在之前程序的基础上加入数据库的功能,如今不使用文件保留了,而使用数据库进行保留。
假如如今要是把一个完整的PersonDAO接口分为StudentDAO和WorkerDAO两个接口,则调用途就不必修复代码。
数据库使用的是mysql,所以需求单独安装一个数据库的驱动程序
##################Michael分割线##########################
PersonDAO.java
packageorg.michael.demo.dao;
importjava.util.Set;
importorg.michael.demo.vo.Person;
//定义详细的数据的操作方法
publicinterfacePersonDAO{
/
刺进数据的操作
@paramperson
刺进的是一个人员信息
@return操作成功与否的提示
@throwsException
假如有错误,则把错误抛给调用途管理
/
publicbooleandoCreate(Personperson)throwsException;
/
更新数据操作
@paramperson
更新的详细信息
@return更新成功与否的提示
@throwsException
假如有错误,则把错误抛出
/
publicbooleandoUpdate(Personperson)throwsException;
/
按id删去信息
@paramid
人员的编号
@return删去与否的提示
@throwsException
假如有错误,则在调用途管理
/
publicbooleandoDelete(Stringid)throwsException;
/
由于查询是多个,所以要回来Set集合
@return全面的查询成果,一个Set中包括了多个Person目标
@throwsException
/
publicSetlt<imgsrc="titter.gif"smilieid="9"border="0"alt=""/>ersongt;findAll()throwsException;
/
按id进行查询
@paramid
人员的编号
@return详细的人员信息
@throwsException
/
publicPersonfindById(Stringid)throwsException;
/
按关键词进行查询
@paramkeyWord
输入的关键词
@return回来一组信息
@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;
//查询操作分为两点,要么是查询工人,要么是查询学生
publicPersonDAOImplJDBC(Stringtype){
this();
this.type=type;
}
publicPersonDAOImplJDBC(){
}
publicbooleandoCreate(Personperson)throwsException{
this.dbc=newDataBaseConnection();
booleanflag=false;
try{
PreparedStatementpstmt=null;
//假如传入的是学生,则type为0,假如传入的是工人,则type为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
[零基础学JAVA]JavaSE实践开发-37.MIS信息管理系统实践开发[JDBC].doc

(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)

[下载]11244102848.rar




上一篇:hsqldb快速入门
下一篇:java面试笔试题大汇总《转》