以mysql为例
1、项目里导入proxool jar包。
2、新建proxool.xml文件
内容:
<?xml version="1.0"encoding="UTF-8"?>
<something-else-entirely>
<proxool>
<alias>别名</alias>
<driver-url>jdbc:mysql://地址/库名</driver-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver-properties>
<propertyname="user" value="用户名"/>
<propertyname="password" value="密码"/>
</driver-properties>
<maximum-connection-count>最大连接数</maximum-connection-count>
<minimum-connection-count>最小连接数</minimum-connection-count>
<house-keeping-test-sql>selectCURRENT_DATE</house-keeping-test-sql>
</proxool>
</something-else-entirely>
3、添加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/classes/Proxool.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>adminProxool</servlet-name>
<servlet-class>
org.logicalcobwebs.proxool.admin.servlet.AdminServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>adminProxool</servlet-name>
<url-pattern>/查看路径</url-pattern>
</servlet-mapping>
4、JDBC连接类构造代码
public 类名() {
try {
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
conn =DriverManager.getConnection("proxool.别名");
stmt = conn.createStatement();
} catch (ClassNotFoundException ex) {
System.out.println("ERROR:" + ex.getMessage());
ex.printStackTrace();
} catch (SQLException ex) {
System.out.println("ERROR:" + ex.getMessage());
ex.printStackTrace();
} catch (Exception ex) {
System.out.println("ERROR:" + ex.getMessage());
ex.printStackTrace();
}
}
完成。