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>
<servlet-mapping>
<servlet-name>proxool</servlet-name>
<url-pattern>/pool/admin</url-pattern>
</servlet-mapping>
这里配置后,可以通过 /pool/admin 察看数据库连接的使用情况
如: http://127.0.0.1:8086/testpool//pool/admin
在tomcat 和resin测试通过