使用JAVA连接池作的数据库增删改查

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

ʹÓÃJAVAÁ¬½Ó³Ø×÷µÄÊý¾Ý¿âÔöɾ¸Ä²é.txt¤åÄã²»ÓÃÒ»ÉÏÏß¿´¼ûÝ­ÔÚÏߣ¬¾Í¼±×ÅÒþÉí£¬·ÅÐÄ¡£Ý­²»»áÈ¥²øÄ㡣˵ºÃµÄ²»Àë²»ÆúÏÖÔÚ·´¶ø×Ô¼ºÈ´×ö²»µ½¨roralceUitlPool.javapackagecom.oneworld.util;importjava.sql.Connection;importjava.sql.DriverManager;importjavax.naming.InitialContext;importjavax.sql.DataSource;/***@authormmode**/publicclassoralceUitlPool{staticConnectionconn=null;publicstaticConnectiongetConnection(){InitialContextinitctx;try{initctx=newInitialContext();DataSourceds=(DataSource)initctx.lookup(java:comp/env/jdbc/vodone);conn=ds.getConnection();}catch(Exceptione){e.printStackTrace();}returnconn;}publicstaticConnectionConnectToDB(){try{StringoURL=192.168.5.92;StringoPort=1521;StringoService=smsdb;StringoUser=gtsms;StringoPassword=gtsms;StringsdName=oracle.jdbc.driver.OracleDriver;Class.forName(sdName);StringconnStr=jdbc:oracle:thin:@+oURL+:+oPort+:+oService;conn=DriverManager.getConnection(connStr,oUser,oPassword);}catch(Exceptione){System.out.println(e);}returnconn;}publicstaticvoidmain(String[]args){oralceUitlPooloup=neworalceUitlPool();oup.getConnection();}}DBUtil.javapackagecom.oneworld.util;importjava.sql.Connection;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;/*******ʹÓÃÁ¬½Ó³ØÁ¬½ÓÊý¾Ý¿â,Ìṩ¶ÔÊý¾Ý¿â²Ù×÷µÄ¸÷¸ö½Ó¿Ú*@authormmode**/publicclassDBUtil{privateConnectionconn=null;privateStatementstmt=null;privateResultSetrs=null;publicDBUtil(){//conn=oralceUitlPool.getConnection();conn=oralceUitlPool.ConnectToDB();try{stmt=conn.createStatement();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}/**************Êý¾Ý¿â²Ù×÷----Ôö¼Ó*@paramsql:½«ÒªÖ´ÐеÄSQLÓï¾ä*@return£ºÖ´Ðгɹ¦ÁË£¬·µ»Øtrue,Ö´Ðв»³É¹¦£¬·µ»Øfalse*/publicbooleanExeInser(Stringsql){booleanflag=true;try{stmt.execute(sql);flag=true;}catch(SQLExceptione){flag=false;e.printStackTrace();}returnflag;}/*********Êý¾Ý¿â²Ù×÷----ɾ³ý*@paramsql:½«ÒªÖ´ÐеÄSQLÓï¾ä*@return:Ö´Ðгɹ¦£¬·µ»Øtrue£¬Ö´ÐÐʧ°Ü£¬·µ»Øfalse;*@throwsSQLException*/publicbooleanExeDel(Stringsql)throwsSQLException{booleanflag=true;try{stmt.execute(sql);flag=true;}catch(SQLExceptione){flag=false;e.printStackTrace();}returnflag;}/*************Êý¾Ý¿â²Ù×÷----ÐÞ¸Ä*@paramsql:½«ÒªÖ´ÐеÄSQLÓï¾ä*@return:Ö´Ðгɹ¦,·µ»Øtrue,Ö´ÐÐʧ°Ü£¬·µ»Øfalse;*/publicbooleanExeUpdate(Stringsql){booleanflag=true;try{stmt.executeUpdate(sql);flag=true;}catch(SQLExceptione){flag=false;e.printStackTrace();}returnflag;}/***********Êý¾Ý¿â²Ù×÷------²éѯ*@paramsql:½«ÒªÖ´ÐеÄSQLÓï¾ä*@return£ºÖ´Ðгɹ¦£¬·µ»Øtrue,Ö´ÐÐʧ°Ü£¬·µ»Øfalse*/publicbooleanExeSelect(Stringsql){booleanflag=true;try{rs=stmt.executeQuery(sql);flag=true;}catch(SQLExceptione){flag=false;e.printStackTrace();}returnflag;}publicResultSetgetRS(){returnrs;}publicstaticvoidmain(Stringargs[])throwsSQLException{DBUtildbc=newDBUtil();booleanb=dbc.ExeSelect(select*fromgtsms.image_group_item);System.out.print(b);}}±êÇ©:ѧϰ³äµç(JAVA)

1 / 4
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功