Java數(shù)據(jù)庫(kù)連接池連接Oracle過(guò)程詳解
第一步:導(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里寫(xiě):
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ù)庫(kù)連接了,是通過(guò)數(shù)據(jù)庫(kù)連接池連接
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 如何通過(guò)vscode運(yùn)行調(diào)試javascript代碼2. JAVA抽象類(lèi)及接口使用方法解析3. 教你JS更簡(jiǎn)單的獲取表單中數(shù)據(jù)(formdata)4. 測(cè)試模式 - XSL教程 - 55. python b站視頻下載的五種版本6. JavaScript設(shè)計(jì)模式之策略模式實(shí)現(xiàn)原理詳解7. python如何寫(xiě)個(gè)俄羅斯方塊8. 《CSS3實(shí)戰(zhàn)》筆記--漸變?cè)O(shè)計(jì)(一)9. Python結(jié)合百度語(yǔ)音識(shí)別實(shí)現(xiàn)實(shí)時(shí)翻譯軟件的實(shí)現(xiàn)10. 本站用的rss輸出
