proxool配置

不从性能上去比较此连接池的优点,单从其多数据配置的灵活性,和连接池监控的方便性就足可以进行选择。

其配置方法:

jar:

proxool-0.9.1.jar

proxool-cglib.jar

相关的数据库驱动包 

web.xml配置

    <!-- 配置proxool连接池 -->
    <servlet>
        <servlet-name>ServletConfigurator</servlet-name>
        <servlet-class>
            org.logicalcobwebs.proxool.configuration.ServletConfigurator
        </servlet-class>
        <init-param>
            <param-name>propertyFile</param-name>
            <param-value>WEB-INF/classes/proxool.properties</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
   <!-- 连接池监控配置 -->
       <servlet>
        <servlet-name>dbAdmin</servlet-name>
        <servlet-class>
            org.logicalcobwebs.proxool.admin.servlet.AdminServlet
        </servlet-class>
    </servlet>
        <servlet-mapping>
        <servlet-name>dbAdmin</servlet-name>
        <url-pattern>/dbAdmin</url-pattern>
    </servlet-mapping>

proxool.properties配置:

#--------jdbc-----------------
jdbc-0.proxool.alias=proxool
jdbc-0.proxool.driver-class=oracle.jdbc.driver.OracleDriver
jdbc-0.proxool.driver-url=jdbc:oracle:thin:@192.168.101.32:2012:arsystem
jdbc-0.user=lneoms_v4
jdbc-0.password=ar#admin#

jdbc-0.proxool.maximum-connection-count=15
jdbc-0.proxool.prototype-count=4

jdbc-0.proxool.house-keeping-test-sql=select CURRENT_DATE
jdbc-0.proxool.verbose=true
jdbc-0.proxool.statistics=15s,1m,1d
jdbc-0.proxool.statistics-log-level=DEBUG

代码中动态获取连接池:

package com.ultrapower.weekly.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.ultrapower.weekly.servlet.Constants;
import com.ultrapower.weekly.bean.TableSpaceInfo;
  
/**     
 * 持久化适配类    
 * @author zhangxuegang       
 * @version 1.0     
 * @created 2012-7-31 下午03:07:53    
 */

public class DataAdapter {
      
    /**     
     * 执行查询
     * @param sqlStr     
     * @return 
     */
    public ResultSet executeQuery(String sqlStr) {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        StringUtil  strUtils = new StringUtil();
        String alias = strUtils.checkNullString(PropertiesUtils.getProperty("jdbc-0.proxool.alias"));
        try {
        conn = DriverManager.getConnection("proxool." + alias);
        ps = conn.prepareStatement(sqlStr);
        rs = ps.executeQuery();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return rs;
    }
      
}

监控地址:

http://localhost:8080/WeeklyReport/dbAdmin

  

posted @ 2012-08-01 14:23  Mr-sniper  阅读(401)  评论(0编辑  收藏  举报