mysql/ target=_blank class=infotextkey>mysql数据库连接池亲身经验,分享出来,供大家学习参考。
准备文件:
mysql-connector-java-5.0.3-bin.jar 下载地址
proxool-0.9.0RC3.jar 下载地址
在web.xml里添加:
复制代码 代码如下:
<servlet>
<servlet-name>ServletConfigurator</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class>
<init-param>
<param-name>xmlFile</param-name>
<param-value>WEB-INF/db.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>/Admin</url-pattern>
</servlet-mapping>
db.xml
复制代码 代码如下:
<?xml version="1.0" encoding="UTF-8" ?>
<proxool>
<
alias>pmd</alias>
<driver-url>jdbc:mysql://192.168.1.200:3306/pmdl1</driver-url>
<driver-class>org.gjt.mm.mysql.Driver</driver-class>
<statistics>1m,15m,1d</statistics>
<driver-properties>
<property name="user" value="root"/>
<property name="password" value="dfxs$"/>
<property name="characterEncoding" value="UTF-8"/>
<property name="useUnicode" value="true"/>
</driver-properties>
<house-keeping-sleep-time>90000</house-keeping-sleep-time>
<prototype-count>5</prototype-count>
<maximum-connection-count>100</maximum-connection-count>
<minimum-connection-count>10</minimum-connection-count>
<maximum-active-time>60000</maximum-active-time>
</proxool>
在实际试用中,如正常试用mysql链接一样。
比如在jsp中添加:
复制代码 代码如下:
<%@ page import="java.sql.*" %>
<%@ page import="org.logicalcobwebs.proxool.*" %>
<%@ page import="org.logicalcobwebs.proxool.configuration.*" %>
然后:
复制代码 代码如下:
Connection conn = null;
try {
// PropertyConfigurator.configure("Proxool.properties");
conn = DriverManager.getConnection("proxool.test");
……
test是 配置文件中的别名。