人员管理程序讲解学习.docx

上传人:b****5 文档编号:7367340 上传时间:2023-05-11 格式:DOCX 页数:12 大小:17.49KB
下载 相关 举报
人员管理程序讲解学习.docx_第1页
第1页 / 共12页
人员管理程序讲解学习.docx_第2页
第2页 / 共12页
人员管理程序讲解学习.docx_第3页
第3页 / 共12页
人员管理程序讲解学习.docx_第4页
第4页 / 共12页
人员管理程序讲解学习.docx_第5页
第5页 / 共12页
人员管理程序讲解学习.docx_第6页
第6页 / 共12页
人员管理程序讲解学习.docx_第7页
第7页 / 共12页
人员管理程序讲解学习.docx_第8页
第8页 / 共12页
人员管理程序讲解学习.docx_第9页
第9页 / 共12页
人员管理程序讲解学习.docx_第10页
第10页 / 共12页
人员管理程序讲解学习.docx_第11页
第11页 / 共12页
人员管理程序讲解学习.docx_第12页
第12页 / 共12页
亲,该文档总共12页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

人员管理程序讲解学习.docx

《人员管理程序讲解学习.docx》由会员分享,可在线阅读,更多相关《人员管理程序讲解学习.docx(12页珍藏版)》请在冰点文库上搜索。

人员管理程序讲解学习.docx

人员管理程序讲解学习

(1)packageorg.lxh.useradmin.dao;

importjava.util.List;

importorg.lxh.useradmin.vo.User;

publicinterfaceIUserDAO{

/**

*表示数据库的增加操作

*

*@paramuser

*@return

*@throwsException

*/

publicbooleandoCreate(Useruser)throwsException;

publicbooleandoUpdate(Useruser)throwsException;

/**

*表示删除操作,按编号删除

*

*@paramid

*@return

*@throwsException

*/

publicbooleandoDelete(intid)throwsException;

/**

*表示数据库的查询操作

*@paramid

*@return

*@throwsException

*/

publicUserfindById(intid)throwsException;

/**

*查询的时候将返回一组对象

*@paramkeyWord

*@return

*@throwsException

*/

publicListfindAll(StringkeyWord)throwsException;

}

(2)packageorg.lxh.useradmin.dao.impl;

importjava.sql.Connection;

importjava.sql.PreparedStatement;

importjava.sql.ResultSet;

importjava.util.ArrayList;

importjava.util.List;

importorg.lxh.useradmin.dao.IUserDAO;

importorg.lxh.useradmin.dbc.DataBaseConnection;

importorg.lxh.useradmin.vo.User;

publicclassIUserDAOImplimplementsIUserDAO{

privateDataBaseConnectiondbc=null;

privateConnectionconn=null;

publicIUserDAOImpl(){

this.dbc=newDataBaseConnection();

this.conn=this.dbc.getConnection();

}

@Override

publicbooleandoCreate(Useruser)throwsException{

booleanflag=false;

PreparedStatementpstmt=null;

Stringsql="INSERTINTOuser(name,sex,birthday)VALUES(?

?

?

)";

try{

pstmt=this.conn.prepareStatement(sql);

pstmt.setString(1,user.getName());//所有的内容从user类中取出

pstmt.setString(2,user.getSex());//所有的内容从user类中取出

pstmt.setDate(3,newjava.sql.Date(user.getBirthday().getTime()));

if(pstmt.executeUpdate()>0){//至少已经更新了一行

flag=true;

}

}catch(Exceptione){

throwe;

}finally{//不管如何抛出,最终肯定是要进行数据库的关闭操作的

if(pstmt!

=null){

try{

pstmt.close();

}catch(Exceptione1){

}

}

this.dbc.close();

}

returnflag;

}

@Override

publicbooleandoDelete(intid)throwsException{

booleanflag=false;

PreparedStatementpstmt=null;

Stringsql="DELETEFROMuserWHEREid=?

";

try{

pstmt=this.conn.prepareStatement(sql);

pstmt.setInt(1,id);//所有的内容从user类中取出

if(pstmt.executeUpdate()>0){//至少已经更新了一行

flag=true;

}

}catch(Exceptione){

throwe;

}finally{//不管如何抛出,最终肯定是要进行数据库的关闭操作的

if(pstmt!

=null){

try{

pstmt.close();

}catch(Exceptione1){

}

}

this.dbc.close();

}

returnflag;

}

@Override

publicbooleandoUpdate(Useruser)throwsException{

booleanflag=false;

PreparedStatementpstmt=null;

Stringsql="UPDATEuserSETname=?

sex=?

birthday=?

WHEREid=?

";

try{

pstmt=this.conn.prepareStatement(sql);

pstmt.setString(1,user.getName());//所有的内容从user类中取出

pstmt.setString(2,user.getSex());//所有的内容从user类中取出

pstmt.setDate(3,newjava.sql.Date(user.getBirthday().getTime()));

pstmt.setInt(4,user.getId());

if(pstmt.executeUpdate()>0){//至少已经更新了一行

flag=true;

}

}catch(Exceptione){

throwe;

}finally{//不管如何抛出,最终肯定是要进行数据库的关闭操作的

if(pstmt!

=null){

try{

pstmt.close();

}catch(Exceptione1){

}

}

this.dbc.close();

}

returnflag;

}

@Override

publicListfindAll(StringkeyWord)throwsException{

Listall=newArrayList();

PreparedStatementpstmt=null;

Stringsql="SELECTid,name,sex,birthdayFROMuserWHEREnameLIKE?

ORsexLIKE?

ORbirthdayLIKE?

";

try{

pstmt=this.conn.prepareStatement(sql);

pstmt.setString(1,"%"+keyWord+"%");

pstmt.setString(2,"%"+keyWord+"%");

pstmt.setString(3,"%"+keyWord+"%");

ResultSetrs=pstmt.executeQuery();//执行查询操作

while(rs.next()){

Useruser=newUser();

user.setId(rs.getInt

(1));

user.setName(rs.getString

(2));

user.setSex(rs.getString(3));

user.setBirthday(rs.getDate(4));

all.add(user);//所有的内容向集合中插入

}

rs.close();

}catch(Exceptione){

throwe;

}finally{//不管如何抛出,最终肯定是要进行数据库的关闭操作的

if(pstmt!

=null){

try{

pstmt.close();

}catch(Exceptione1){

}

}

this.dbc.close();

}

returnall;

}

@Override

publicUserfindById(intid)throwsException{

Useruser=null;

PreparedStatementpstmt=null;

Stringsql="SELECTid,name,sex,birthdayFROMuserWHEREid=?

";

try{

pstmt=this.conn.prepareStatement(sql);

pstmt.setInt(1,id);

ResultSetrs=pstmt.executeQuery();//执行查询操作

if(rs.next()){

user=newUser();

user.setId(rs.getInt

(1));

user.setName(rs.getString

(2));

user.setSex(rs.getString(3));

user.setBirthday(rs.getDate(4));

}

rs.close();

}catch(Exceptione){

throwe;

}finally{//不管如何抛出,最终肯定是要进行数据库的关闭操作的

if(pstmt!

=null){

try{

pstmt.close();

}catch(Exceptione1){

}

}

this.dbc.close();

}

returnuser;

}

}

(3)packageorg.lxh.useradmin.dbc;

importjava.sql.Connection;

importjava.sql.DriverManager;

importjava.sql.SQLException;

publicclassDataBaseConnection{

privatestaticfinalStringDBDRIVER="org.gjt.mm.mysql.Driver";

privatestaticfinalStringDBURL="jdbc:

mysql:

//localhost:

3306/mldn";

privatestaticfinalStringDBUSER="root";

privatestaticfinalStringDBPASS="mysqladmin";

privateConnectionconn=null;

publicDataBaseConnection(){

try{

Class.forName(DBDRIVER);

}catch(ClassNotFoundExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

try{

conn=DriverManager.getConnection(DBURL,DBUSER,DBPASS);

}catch(SQLExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

}

publicConnectiongetConnection(){

returnthis.conn;

}

publicvoidclose(){

if(this.conn!

=null){

try{

this.conn.close();

}catch(SQLExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

}

}

}

(4)packageorg.lxh.useradmin.factory;

importorg.lxh.useradmin.dao.IUserDAO;

importorg.lxh.useradmin.dao.impl.IUserDAOImpl;

publicclassDAOFactory{

publicstaticIUserDAOgetIUserDAOInstance(){

returnnewIUserDAOImpl();

}

}

(5)packageorg.lxh.useradmin.test;

importjava.util.Iterator;

importjava.util.List;

importorg.lxh.useradmin.factory.DAOFactory;

importorg.lxh.useradmin.vo.User;

publicclassTestAll{

publicstaticvoidmain(String[]args)throwsException{

ListallUser=DAOFactory.getIUserDAOInstance().findAll("");

Iteratoriter=allUser.iterator();

while(iter.hasNext()){

Useruser=iter.next();

System.out.println(user);

}

}

}

packageorg.lxh.useradmin.test;

importorg.lxh.useradmin.factory.DAOFactory;

publicclassTestDelete{

publicstaticvoidmain(String[]args)throwsException{

DAOFactory.getIUserDAOInstance().doDelete

(2);

}

}

packageorg.lxh.useradmin.test;

importorg.lxh.useradmin.factory.DAOFactory;

importorg.lxh.useradmin.vo.User;

publicclassTestId{

publicstaticvoidmain(String[]args)throwsException{

Useruser=DAOFactory.getIUserDAOInstance().findById

(1);

System.out.println(user);

}

}

packageorg.lxh.useradmin.test;

importjava.util.Date;

importorg.lxh.useradmin.factory.DAOFactory;

importorg.lxh.useradmin.vo.User;

publicclassTestInsert{

publicstaticvoidmain(String[]args)throwsException{

Useruser=newUser();

user.setName("李兴华");

user.setSex("男");

user.setBirthday(newDate());

DAOFactory.getIUserDAOInstance().doCreate(user);

}

}

packageorg.lxh.useradmin.test;

importjava.util.Date;

importorg.lxh.useradmin.factory.DAOFactory;

importorg.lxh.useradmin.vo.User;

publicclassTestUpdate{

publicstaticvoidmain(String[]args)throwsException{

Useruser=newUser();

user.setName("张心");

user.setSex("女");

user.setId

(2);

user.setBirthday(newDate());

DAOFactory.getIUserDAOInstance().doUpdate(user);

}

}

(6)DROPTABLEuser;

CREATETABLEuser(

idINTAUTO_INCREMENTPRIMARYKEY,

nameVARCHAR(50)NOTNULL,

sexVARCHAR(10)NOTNULL,

birthdayDATE

);

(7)packageorg.lxh.useradmin.vo;

importjava.util.Date;

publicclassUser{

privateintid;

publicintgetId(){

returnid;

}

publicvoidsetId(intid){

this.id=id;

}

publicStringgetName(){

returnname;

}

publicvoidsetName(Stringname){

this.name=name;

}

publicStringgetSex(){

10元以下□10~50元□50~100元□100元以上□returnsex;

}

publicvoidsetSex(Stringsex){

4、如果学校开设一家DIY手工艺制品店,你是否会经常去光顾?

this.sex=sex;

自制性手工艺品。

自制饰品其实很简单,工艺一点也不复杂。

近两年来,由于手机的普及,自制的手机挂坠特别受欢迎。

}

publicDategetBirthday(){

十字绣□编制类□银饰制品类□串珠首饰类□returnbirthday;

在大学生对DIY手工艺品价位调查中,发现有46%的女生认为在十元以下的价位是可以接受;48%的认为在10-15元;6%的则认为50-100元能接受。

如图1-2所示}

1.www。

cer。

net/artide/2004021313098897。

shtml。

(三)DIY手工艺品的“自助化”publicvoidsetBirthday(Datebirthday){

新材料手工艺品。

目前,国际上传统的金银、仿金银制成饰品的销售在逐步下降,与此形成鲜明对比的是,数年以前兴起的崇尚然风格、追求个性的自制饰品--即根据自己的创意将各种材质的饰珠,用皮、布、金属等线材串出的品,正在各国的女性中大行其道。

this.birthday=birthday;

}

§8-2购物环境与消费行为2004年3月20日privateStringname;

privateStringsex;

privateDatebirthday;

@Override

publicStringtoString(){

return"编号:

"+this.id+";姓名:

"+this.name+";性别:

"+this.sex

10元以下□10~50元□50~100元□100元以上□+";生日:

"+this.birthday;

}

}

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2