天天看点

proxool数据库连接池使用实例

proxool数据库连接池使用实例

1. 引入 proxool-0.8.3.jar

2. 创建配置文件:

pool_aspboy.xml

<?xml version="1.0" encoding="iso-8859-1"?>

<!-- the proxool configuration can be embedded within your own application's.

anything outside the "proxool" tag is ignored. -->

<something-else-entirely>

  <proxool>

    <alias>jxc</alias>

<driver-url>jdbc:mysql://127.0.0.1:3306/jxc?useunicode=true&characterencoding=gbk</drive

r-url>

    <driver-class>com.mysql.jdbc.driver</driver-class>

    <driver-properties>

      <property name="user" value="root"/>

      <property name="password" value="root"/>

    </driver-properties>

    <!--<maximum-active-time>3</maximum-active-time>-->

    <minimum-connection-count>1</minimum-connection-count>

    <maximum-connection-count>20</maximum-connection-count>

    <!--<house-keeping-test-sql>select getdate() as nowdate</house-keeping-test-sql>-->

  </proxool>

</something-else-entirely>

其中<alias>jxc</alias>  为别名

调用:

 public static connection getconnection(final string poolname)

   throws sqlexception {

  try {

   return drivermanager.getconnection(poolname);

  } catch (exception e) {

   return null;

  }

 }

其中 poolname 传入:  proxool.jxc  就是 proxool.别名

同时需要在配置文件中配置

web.xml中 通过servlet初始化连接池

  <servlet>

          <servlet-name>proxoolinitialservlet</servlet-name>

<servlet-class>org.logicalcobwebs.proxool.configuration.servletconfigurator</servlet-class>

         <init-param>

                 <param-name>xmlfile</param-name>

                 <param-value>web-inf//pool_aspboy.xml</param-value>

          </init-param>

           <load-on-startup>1</load-on-startup>

</servlet>

<servlet>

  <servlet-name>proxool</servlet-name>

  <servlet-class>org.logicalcobwebs.proxool.admin.servlet.adminservlet</servlet-class>

<servlet-mapping>

  <url-pattern>/pool/admin</url-pattern>

</servlet-mapping>

这里配置后,可以通过 /pool/admin 察看数据库连接的使用情况

如: http://127.0.0.1:8086/testpool//pool/admin

在tomcat 和resin测试通过