需要的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
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>LikeReading</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>LikeReading.root</param-value>
</context-param>
<!------proxool配置--------------->
<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>
<!------proxool配置--------------->
<servlet>
<servlet-name>UserCtxServlet</servlet-name>
<servlet-class>cn.twt.svx.controllers.UserCtxServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UserCtxServlet</servlet-name>
<url-pattern>/UserCtx.do</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>BookCtxServlet</servlet-name>
<servlet-class>cn.twt.svx.controllers.BookCtxServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BookCtxServlet</servlet-name>
<url-pattern>/BookCtx.do</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>HomeCtrlServlet</servlet-name>
<servlet-class>cn.twt.svx.controllers.HomeCtrlServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>proxool</servlet-name>
<url-pattern>/proxool</url-pattern>
</servlet-mapping>
<filter>
<filter-name>setCharacterEncoding</filter-name>
<filter-class>cn.twt.svx.filter.EncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>setCharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>logfilter</filter-name>
<filter-class>cn.twt.svx.filter.LogFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>logfilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet-mapping>
<servlet-name>HomeCtrlServlet</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>HomeCtrlServlet</servlet-name>
<url-pattern>/index.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>HomeCtrlServlet</servlet-name>
<url-pattern>/index.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>HomeCtrlServlet</servlet-name>
<url-pattern>/index.php</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>HomeCtrlServlet</servlet-name>
<url-pattern>/index.asp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>HomeCtrlServlet</servlet-name>
<url-pattern>/index.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>3600000</session-timeout>
</session-config>
<error-page>
<error-code>404</error-code>
<location>/NotFound.jsp</location>
</error-page>
<error-page>
<exception-type>exception.ServletNotFound</exception-type>
<location>/sorry.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/sorry.jsp</location>
</error-page>
</web-app>
连接工具类
package cn.twt.svx.utils;
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);
}
}
}
}