Java數(shù)據(jù)庫連接池連接Oracle過程詳解
第一步:導(dǎo)入tomcatlib 下的一個(gè)tomcat-dbcp.jar包
第二步:在webMETA-INF下新建一個(gè)context.xml文件,文件內(nèi)容如下:
<?xml version='1.0' encoding='UTF-8'?><Context><Resource name='jdbc/lwl' auth='Container'type='javax.sql.DataSource'driverClassName='oracle.jdbc.driver.OracleDriver'url='jdbc:oracle:thin:@192.168.1.3:1521:xe'username='lwl'password='123456'maxActive='5'maxIdle='2'maxWait='5000'/></Context>
第三步:在Dao里的getConn里寫:
private static Connection getConn() {Connection conn = null;try {Context ctx = new InitialContext();DataSource ds = (DataSource) ctx.lookup('java:comp/env/jdbc/lwl');conn = ds.getConnection();} catch (Exception e) {System.err.println('error:' + e.getMessage());}return conn;}
此時(shí)后面再調(diào)用getConn方法,就不是直接跟數(shù)據(jù)庫連接了,是通過數(shù)據(jù)庫連接池連接
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. java volatile案例講解2. 在layer彈出層中通過ajax返回html拼接字符串填充數(shù)據(jù)的方法3. JSP的Cookie在登錄中的使用4. ztree+ajax實(shí)現(xiàn)文件樹下載功能5. 存儲于xml中需要的HTML轉(zhuǎn)義代碼6. asp.net core 中的Jwt(Json Web Token)的使用詳解7. 編寫xml沒有代碼提示的解決方法8. 用xslt將xml解析成xhtml的代碼9. jsp實(shí)現(xiàn)textarea中的文字保存換行空格存到數(shù)據(jù)庫的方法10. 解決Ajax方式上傳文件報(bào)錯(cuò)"Uncaught TypeError: Illegal invocation"
