需要的jar包包括
jar包名称 | 功能 | 下载地址 |
proxool-0.9.1.jar | proxool核心包 | |
proxool-cglib-0.9.1.jar | proxool连接池组件 | |
mysql-connector-java-5.1.36 | mysql数据库驱动 | |
log4j-1.2.15.jar | 日志 | |
commons-lang-2.4.jar | common工具 | |
commons-logging-1.1.1.jar | common 日志 |
WEB-INF/proxool-mysql.xml
<?xml version="1.0" encoding="UTF-8"?>
<something-else-entirely>
<proxool>
<alias>mysql</alias>
<driver-url>
jdbc:mysql://localhost:3306/likereading
</driver-url>
<driver-class>
com.mysql.jdbc.Driver
</driver-class>
<driver-properties>
<property name="user" value="root" />
<property name="password" value="root" />
</driver-properties>
<maximum-connection-count>100</maximum-connection-count>
<prototype-count>15</prototype-count>
<minimum-connection-count>5</minimum-connection-count>
<maximum-active-time>1000</maximum-active-time>
<house-keeping-sleep-time>30000</house-keeping-sleep-time>
<house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
</proxool>
</something-else-entirely>
WEB-INF/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/proxool-mysql.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>
连接工具类
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class DBFactory
{
private static DBFactory instance = null;
public static Log log = LogFactory.getLog(DBFactory.class);
private DBFactory()
{
try
{
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
}
catch (ClassNotFoundException e)
{
log.error(e.getLocalizedMessage(), e);
}
}
public static DBFactory getInstance()
{
if (instance == null) {
synchronized (DBFactory.class)
{
if (instance == null) {
instance = new DBFactory();
}
}
}
return instance;
}
public Connection getConnection()
{
Connection conn = null;
try
{
conn = DriverManager.getConnection("proxool.mysql");
}
catch (SQLException e)
{
e.printStackTrace();
}
return conn;
}
public static void quietClose(Connection sqlConn)
{
if (sqlConn != null) {
try
{
sqlConn.close();
}
catch (SQLException e)
{
e.printStackTrace();
log.error(e.getLocalizedMessage(), e);
}
}
}
}