WEB开发网
开发学院软件开发Java Tomcat DBCP配置方法 阅读

Tomcat DBCP配置方法

 2009-09-26 00:00:00 来源:WEB开发网   
核心提示: 第二步:修改C:"eclipse-SDK-3.0.1-win32"eclipse"workspace"zlp"WebContent"WEB-INF下web.xml,在<web-app>…..</web-a

第二步:修改C:"eclipse-SDK-3.0.1-win32"eclipse"workspace"zlp"WebContent"WEB-INF下web.xml,在<web-app>…..</web-app>中增加一级元素如下:

<!-- Database Config start -->
<resource-ref>
<description>connectDB test</description>
<res-ref-name>jdbc/testdb0_cs</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<!-- Database Config end -->

说明:蓝色的路径是你的应用所在路径下的web.xml

第三步:将Informix JDBC Driver拷贝到C:"Tomcat 5.0"common"lib目录下

第四步:重新启动tomcat

二、Tomcat中配置多个数据源的方法

第一步:server.xml 蓝色和绿色部分是两个数据源,分别连接两个不同的数据库。依次类推,配置多个。

<DefaultContext>
          <Resource name="jdbc/testdb0_cs1" auth="Container" type="javax.sql.DataSource"/>
          <ResourceParams name="jdbc/testdb0_cs1">
            <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.179.208:6666/testdb0_cs1:INFORMIXSERVER=ccbhr_test</value>
            </parameter>
            <parameter>
              <name>username</name>
              <value>informix</value>
            </parameter>
            <parameter>
              <name>password</name>
              <value>google</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>
          <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>informix</value>
            </parameter>
            <parameter>
              <name>password</name>
              <value>informix</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>

Tags:Tomcat DBCP 配置

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接