如何在Tomcat 6中配置BoneCP数据源

1) 将bonecp-0.7.1.RELEASE.jar, slf4j-log4j12-1.5.11.jar, slf4j-api-1.5.11.jar, guava-r08.jar 拷贝到$CATALINA_HOME/lib中

2) 打开$CATALINA_HOME/server.xml,在Context节点内添加BoneCP数据源:

<Resource type="com.jolbox.bonecp.BoneCPDataSource"
            name="jdbc/BoneCPPool"
	     auth="Container"
             factory="org.apache.naming.factory.BeanFactory"
             driverClass="com.mysql.jdbc.Driver"
            jdbcUrl="jdbc:mysql://localhost:3306/lportal?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false"
            username="root"
            password="1234"
         idleMaxAgeInMinutes="5"
         idleConnectionTestPeriodInMinutes="1"
         partitionCount="3"
         acquireIncrement="5"
         maxConnectionsPerPartition="10"
         minConnectionsPerPartition="5"
         statementsCacheSize="50"
         releaseHelperThreads="5"
	 logStatementsEnabled="true" 
         />   


3) 在Java web应用的web.xml中引用数据源:

<resource-ref>
        <description>Oracle Development Datasource</description>
        <res-ref-name>jdbc/BoneCPPool</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
</resource-ref>


4) 在Java代码中的引用:

Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/BoneCPPool");
Connection con = ds.getConnection();





你可能感兴趣的:(tomcat,bonecp)