论坛首页 Java企业应用论坛

proxool配置及测试(数据库用的MySQL)

浏览 2817 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (1) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-10-14   最后修改:2009-10-14

Proxool连接池是sourceforge下的一个开源项目,这个项目提供一个健壮、易用的连接池,最为关键的是

这个连接池提供监控的功能,方便易用,便于发现连接泄漏的情况。开源项目地址是:

http://proxool.sourceforge.net/ 配置连接池比较的简单:

1.需要用到的jar包:

i.proxool的下载地址: http://proxool.sourceforge.net/download.html
需要lib文件夹下的两个jar包(目前的版本是:proxool-0.9.1.jar)

ii.commons-logging.jar的下载地址:http://commons.apache.org/downloads/download_logging.cgi
解压后用commons-logging-版本号.jar(目前的版本是commons-logging-1.1.1.jar)

iii.相应数据库的驱动程序(我用的是:mysql-connector-java-5.1.6-bin.jar)

把这些jar包导入工程

2.在 WEB-INF 下,建立一个文件: proxool.xml,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!-- the proxool configuration can be embedded within your own application's.
Anything outside the "proxool" tag is ignored. -->

<something-else-entirely>
<proxool>
<alias>mydata</alias>
<driver-url>
jdbc:mysql://localhost:3306/test
</driver-url>
<driver-class>
org.gjt.mm.mysql.Driver 
</driver-class>
<driver-properties>
<property name="user" value="root" />
<property name="password" value="root" />
</driver-properties>
<maximum-connection-count>10</maximum-connection-count>
<house-keeping-test-sql>
select CURRENT_DATE
</house-keeping-test-sql>
</proxool>
</something-else-entirely>

 
3.修改web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<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/proxool.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>Admin</servlet-name>
<servlet-class>
org.logicalcobwebs.proxool.admin.servlet.AdminServlet
</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Admin</servlet-name>
<url-pattern>/Admin</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

 


4.测试的jsp文件

<%@ page import="java.sql.*"%>
<%@ page contentType="text/html;charset=GB2312"%>
<html>
<head>
<title>proxool测试</title>
</head>
<body>
<h2>
使用 Proxool Connection Pool,用xml文件配置
</h2>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
conn = DriverManager.getConnection("proxool.mydata");
stmt = conn.createStatement();

out.println("<br />数据库连接成功<br /><br />");

String query = "select now()";
rs = stmt.executeQuery(query);

while (rs.next()) {
out.print(rs.getString(1) + "--OK<br />");
}

stmt.close();
conn.close();
} catch (SQLException sqle) {
out.println("sqle=" + sqle);
out.println("<br />数据库连接失败<br /><br />");
} finally {
if(stmt != null){
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn != null){
try {
conn.close();
out.println("<br />数据库关闭成功<br />");
} catch (SQLException e) {
e.printStackTrace();
out.println("数据库关闭失败<br />");
}
}
}
%>
</body>
</html>

 
5、后台统计与信息

请进入:http://127.0.0.1:8080/testproxool/Admin
(testpxool1应改为你的WEB应用程序名)


参考文章:
1.http://www.java3z.com/cwbwebhome/article/article1a/134.jsp?id=213
2.http://www.blogjava.net/mimi-van/archive/2008/03/21/168754.html
3.http://blog.csdn.net/a_heng/archive/2008/07/04/2611585.aspx

 

论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics