如何配置mysql连接池的proxool环境
1个回答
2016-12-06
展开全部
proxool连接池在tomcat+MySQL环境下的配置
proxool是一个开源的连接池,性能优异,最好的是:即时监控连接池状态。
1、把proxool库文件放在WEB-INF/lib/,建立WEB-INF/db.xml,内容大概如下:
<?xml version="1.0" encoding="UTF-8" ?>
<proxool>
<alias>mysql</alias>
<driver-url>jdbc:mysql://localhost/dmim</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="123456"/>
</driver-properties>
<maximum-connection-count>100</maximum-connection-count>
<minimum-connection-count>25</minimum-connection-count>
<maximum-active-time>60000</maximum-active-time>
<house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
</proxool>
2、在WEB-INF/web.xml中<web-app>节点里加入如下内容:
<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>/proxool</url-pattern>
</servlet-mapping>
3、在需要连接数据库时,只需要写:
Connection conn = null;
conn = DriverManager.getConnection("proxool.mysql");
其它像conn.createStatement();和conn.prepareStatement(sql);之类的操作都和原来一样。
关闭连接一定要注意在catch 和 final里也要关闭
4、测试用例:
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="Java.sql.*,javax.naming.*"%>
<%
try {
Connection conn = DriverManager.getConnection("proxool.mysql");
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
String strSQL = "SELECT * FROM consumer";
ResultSet rs = stmt.executeQuery(strSQL);
while(rs.next()){
out.println(rs.getString(2));
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
...ccccccccccccccccccccccccc
</html>
<%
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
%>
proxool是一个开源的连接池,性能优异,最好的是:即时监控连接池状态。
1、把proxool库文件放在WEB-INF/lib/,建立WEB-INF/db.xml,内容大概如下:
<?xml version="1.0" encoding="UTF-8" ?>
<proxool>
<alias>mysql</alias>
<driver-url>jdbc:mysql://localhost/dmim</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="123456"/>
</driver-properties>
<maximum-connection-count>100</maximum-connection-count>
<minimum-connection-count>25</minimum-connection-count>
<maximum-active-time>60000</maximum-active-time>
<house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
</proxool>
2、在WEB-INF/web.xml中<web-app>节点里加入如下内容:
<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>/proxool</url-pattern>
</servlet-mapping>
3、在需要连接数据库时,只需要写:
Connection conn = null;
conn = DriverManager.getConnection("proxool.mysql");
其它像conn.createStatement();和conn.prepareStatement(sql);之类的操作都和原来一样。
关闭连接一定要注意在catch 和 final里也要关闭
4、测试用例:
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="Java.sql.*,javax.naming.*"%>
<%
try {
Connection conn = DriverManager.getConnection("proxool.mysql");
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
String strSQL = "SELECT * FROM consumer";
ResultSet rs = stmt.executeQuery(strSQL);
while(rs.next()){
out.println(rs.getString(2));
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
...ccccccccccccccccccccccccc
</html>
<%
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询