欢迎来到天天文库
浏览记录
ID:12919367
大小:73.00 KB
页数:11页
时间:2018-07-19
《jsp+servlet+javabean自我大总结常用模式》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、jsp+servlet+javaBean自我大总结常用模式第一步:建一个操作员表。createtableTOPERATOR(OPERATOR_IDNVARCHAR2(20)primarykey,OPERATOR_NAMEVARCHAR2(20),OPERATOR_PWDVARCHAR2(20),IS_ADMINCHAR(1))第二步:创建javaBean/**o*操作实体类**@authorchenlijiang2010-12-1*/publicclassOperatorimplementsSerializable{privatestaticfinallongserialVe
2、rsionUID=1L;publicstaticfinalintADMIN=1;publicstaticfinalintOPER=2;privateStringoperator_id;privateStringoperator_name;privateStringoperator_pwd;privateStringis_admin;publicStringgetOperator_id(){returnoperator_id;}publicvoidsetOperator_id(StringoperatorId){operator_id=operatorId;}publicStringgetOp
3、erator_name(){returnoperator_name;}publicvoidsetOperator_name(StringoperatorName){operator_name=operatorName;}publicStringgetOperator_pwd(){returnoperator_pwd;}publicvoidsetOperator_pwd(StringoperatorPwd){operator_pwd=operatorPwd;}publicStringgetIs_admin(){returnis_admin;}publicvoidsetIs_admin(Stri
4、ngisAdmin){is_admin=isAdmin;}}第三步:建立一个类,封装所有数据库操作/***把对数据库的操作放在本类中。update:对数据库的修改操作select:查询数据库中的数据**@authorchenlijiang2010-12-14*/publicclassDbUtil{privatefinalStringurl;privatefinalStringuser;privatefinalStringpassword;privatefinalThreadLocalth=newThreadLocal();static{try{
5、Class.forName("oracle.jdbc.OracleDriver");}catch(ClassNotFoundExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}privateDbUtil(){url="jdbc:oracle:thin:@localhost:1521:orcl";user="system";password="orcl";}//单例模式privatestaticDbUtildbUtil;publicstaticDbUtilgetDbUtil(){if(dbUtil==null){dbU
6、til=newDbUtil();}returndbUtil;}//获得Connection连接publicConnectiongetConnection(){Connectionconn=th.get();if(conn==null){try{conn=DriverManager.getConnection(url,user,password);//conn.setAutoCommit(false);th.set(conn);}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}returnconn
7、;}//关闭连接publicvoidcloseConnection(){Connectionconn=th.get();if(conn!=null){try{th.remove();//conn.commit();conn.close();System.out.println("closeConnection启动>>>>>>>>>>>>");}catch(SQLExceptione){//TODOAuto-g
此文档下载收益归作者所有