第一种方法:
1、conf/server.xml中GlobalNamingResources里面添加:
<Resource name="jdbc/DBPool"
auth="Container" type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
maxIdle="20"
maxWait="5000"
username="admin"
password="admin"
url="jdbc:oracle:thin:@192.168.1.8:1521:orcl"
maxActive="100"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"/>
name:指定资源池的Resource的jndi的名字,即:给连接池起的名字
auth:管理权限。指定管理Resource的Manager。可以是container或Application
type:
driverClassName:连接池数据库驱动
maxIdle:连接池中最多可空闲的连接
maxWait:连接池中连接用完时,新的请求等待时间
username:数据库用户名
password:数据库密码
url:数据库连接字符串
maxActive:连接池支持的最大连接数
removeAbandonedTimeout:活动连接的最大空闲时间,针对未被close的活动连接
removeAbandoned:是否清理removeAbandonedTimeout秒没有使用的活动连接,清理后并没有放回连接池
logAbandoned:连接池收回空闲的活动连接时是否打印消息
2、conf/context.xml中context中添加:
<ResourceLink name="jdbc/DBPool" global="jdbc/DBPool" type="javax.sql.DataSource"/>
name名称跟server.xml中的name一致。
3、项目中的web.xml的web-app中添加
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/DBPool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
res-ref-name的名称跟1、2中的一致。
第二种方法:
1、WebRoot\META-INF下添加context.xml文件
内容为:
<?xml version='1.0' encoding='utf-8'?>
<Context>
<Resource name="jdbc/DBOracle"
auth="Container" type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
maxIdle="20"
maxWait="5000"
username="admin"
password="admin"
url="jdbc:oracle:thin:@192.168.1.8:1521:orcl"
maxActive="100"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"/>
</Context>
2、程序中的web.xml的web-app中添加
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/DBOracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
res-ref-name和1中的name相同。
此文章由 http://www.ositren.com 收集整理 ,地址为:
http://www.ositren.com/htmls/68249.html