JSP proxool+mysql数据库连接池配置

需要的jar包包括

jar包名称

功能

下载地址

proxool-0.9.1.jar

proxool核心包

http://download.csdn.net/detail/death05/9584749

proxool-cglib-0.9.1.jar

proxool连接池组件

http://download.csdn.net/detail/death05/9584751

mysql-connector-java-5.1.36

mysql数据库驱动 

http://download.csdn.net/detail/death05/9584745

log4j-1.2.15.jar

日志

http://download.csdn.net/detail/death05/9584739

commons-lang-2.4.jar

common工具

http://download.csdn.net/detail/death05/9584753

commons-logging-1.1.1.jar

common 日志

http://download.csdn.net/detail/death05/9584755


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);
      }
    }
  }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值