需要的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
mysql jdbc:mysql://localhost:3306/likereading com.mysql.jdbc.Driver 100 15 5 1000 30000 select CURRENT_DATE
WEB-INF/web.xml
LikeReading webAppRootKey LikeReading.root ServletConfigurator org.logicalcobwebs.proxool.configuration.ServletConfigurator xmlFile WEB-INF/proxool-mysql.xml 1 proxool org.logicalcobwebs.proxool.admin.servlet.AdminServlet UserCtxServlet cn.twt.svx.controllers.UserCtxServlet UserCtxServlet /UserCtx.do BookCtxServlet cn.twt.svx.controllers.BookCtxServlet BookCtxServlet /BookCtx.do HomeCtrlServlet cn.twt.svx.controllers.HomeCtrlServlet proxool /proxool setCharacterEncoding cn.twt.svx.filter.EncodingFilter encoding utf-8 setCharacterEncoding /* logfilter cn.twt.svx.filter.LogFilter logfilter /* HomeCtrlServlet /index.jsp HomeCtrlServlet /index.html HomeCtrlServlet /index.htm HomeCtrlServlet /index.php HomeCtrlServlet /index.asp HomeCtrlServlet /index.do index.jsp index.html 3600000 404 /NotFound.jsp exception.ServletNotFound /sorry.jsp java.lang.NullPointerException /sorry.jsp
连接工具类
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); } } }}