轉帖|其它|編輯:郝浩|2008-09-11 11:35:12.000|閱讀 893 次
概述:tomcat下連接池的配置
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
1.把數據庫JDBC驅動拷貝到%TOMCAT_HOME%/common/lib或%TOMCAT_HOME%/webapps/yourweb/WEB-INF/lib 下;
2.修改tomcat安裝目錄下conf/server.xml,在Host元素下添加一個Context元素,示例:
< Context path="/TomcatPool" docBase="E:\\Tomcat 5.5\\webapps\\TomcatPool" debug="1" reloadable="true">
< Resource name="jdbc/ds" type="javax.sql.DataSource"
driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
url="jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs"
username="sa" password="sa"
maxWait="5000" maxActive="4"
maxIdle="4"/>
< /Context>
3.修改TomcatPool工程的web.xml,添加一個resource-ref元素
< resource-ref>
< description>sqlserverDB connection< /description>
< res-ref-name>jdbc/ds< /res-ref-name>
< res-type>javax.sql.DataSource< /res-type>
< res-auth>Container< /res-auth>
< /resource-ref>
4.調用
javax.naming.Context context = new javax.naming.InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource)context.lookup("java:comp/env/jdbc/ds");
java.sql.Connection conn = ds.getConnection();
對于Tomcat 6,步驟為:
以前的版本要到server.xml中配置,6.0版本以后要到context.xml中配置。
在6.0下只能用這個配置:
< Context docBase="MyZhiNangTuanDemo" path="/MyZhiNangTuanDemo" reloadable="true">
< Resource name="jdbc/mldn" auth="Container"
type="javax.sql.DataSource" maxActive="100" maxIdle="30"
maxWait="10000" username="root" password="123456"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mldn"/>
< ResourceLink global="jdbc/mldn" name="jdbc/mldn" type="javax.sql.DataSource"/>
< /Context>
應用程序的wen.xml也不用配置這個了
< resource-ref>
< description>DB Connection< /description>
< res-ref-name>jdbc/mldn< /res-ref-name>
< res-type>javax.sql.DataSource< /res-type>
< res-auth>Container< /res-auth>
< /resource-ref>
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:IT專家網論壇