本文以tomcat5.0和informix数据库为例,介绍tomcat 单个JNDI数据源和多数据源的配置。
一、Tomcat配置一个jndi数据源方法
第一步:在C:"Tomcat 5.0"conf"server.xml中<Host>….</Host>中增加如下内容,注意:<DefaultContext>属于<Host>下的一级元素。
<DefaultContext>
<Resource name = "jdbc/testdb0_cs" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/testdb0_cs">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.informix.jdbc.IfxDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:informix-sqli://192.177.191.130:6666/testdb0_cs:INFORMIXSERVER=ccbhr_test</value>
</parameter>
<parameter>
<name>username</name>
<value>hrmis</value>
</parameter>
<parameter>
<name>password</name>
<value>hrmis</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>poolPrepareStatements</name>
<value>true</value>
</parameter>
<parameter>
<name>removeAbandoned</name>
<!-- Abandoned DB connections are removed and recycled -->
<value>true</value>
</parameter>
<parameter>
<name>removeAbandonedTimeout</name>
<!-- Use the removeAbandonedTimeout parameter to set the number of seconds a DB connection has been idle before it is considered abandoned. -->
<value>60</value>
</parameter>
<parameter>
<name>logAbandoned</name>
<!-- Log a stack trace of the code which abandoned -->
<value>false</value>
</parameter>
</ResourceParams>
</DefaultContext>