- 论坛徽章:
- 0
|
网址:
http://proxool.sourceforge.net/
当前版本:proxool-0.9.0RC2
1、下载proxool 地址:
http://proxool.sourceforge.net
2、解压缩proxool-0.9.0RC2.zip,拷贝lib/proxool-0.9.0RC2.jar到web-info/lib 拷贝jdbc驱动到web-info/lib
3、在web-info下建立文件:proxool.xml
Test
jdbc:oracle:thin:@192.168.10.160:1521:orc1
oracle.jdbc.driver.OracleDriver
10
select CURRENT_DATE
4、在web.xml里新增如下:
proxoolServletConfigurator
org.logicalcobwebs.proxool.configuration.ServletConfigurator
xmlFile
WEB-INF/config/proxool.xml
1
Admin
org.logicalcobwebs.proxool.admin.servlet.AdminServlet
Admin
/admin
5、在调用数据库连接代码:
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
Connection conn = DriverManager.getConnection("proxool.Test");
6、利用proxool监控工具查看数据库运行状态。地址:./admin
以上配置是采用的XML文件方式,也可以采用properties配置方式:
proxool.alias=Test
proxool.driver-class=oracle.jdbc.driver.OracleDriver
proxool.driver-url=jdbc:oracle:thin:@192.168.10.160:1521:orcl
proxool.user=test
proxool.password=testpass
proxool.maximum-connection-count=20
proxool.prototype-count=4
proxool.house-keeping-test-sql=select sysdate from DUAL
proxool.verbose=true
proxool.statistics=10s,1m,1d
proxool.statistics-log-level=ERROR
ServletConfigurator
org.logicalcobwebs.proxool.configuration.ServletConfigurator
propertyFile
WEB-INF/config/Proxool.properties
1
在调用数据库连接代码
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
Connection conn = DriverManager.getConnection("proxool.Test");
还有一些配置属性:
maximum-connection-lifetime 最大连接生命周期 默认值:4小时
maximum-active-time: 最大活动时间 默认值:5分钟
maximum-connection-count 最大连接数 默认值:15个
minimum-connection-count 最小连接数 默认值:5个
在用admin调用的时候,可以查看这个WEB应用所有的连接数的状态,虽然这个插件可以把不活动的连接自动放到连接池里,但是如果连接数过多,而不及时KILL的话,对网站的连接是有很大的影响的,建议还是手工KILL。
---上面是介绍Proxool怎么使用
---下面就是一个连接的实例:
public class ConnDB {
private Logger logger=Logger.getLogger(ConnDB.class);
private Connection conn=null;
private Statement stmt=null;
private ResultSet rs=null;
/**
* 获取数据库连接
* @return
*/
public Connection getConn(){
try {
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
conn=DriverManager.getConnection("proxool.test");
} catch (ClassNotFoundException e) {
logger.error("getConn()", e);
} catch (SQLException e) {
logger.error("getConn()获取数据库连接池时出错!", e);
}
return conn;
}
/**
* 执行查询语句sql
* @param sql
* @return
*/
public ResultSet getResultSet(String sql){
try {
if(conn==null||conn.isClosed()) conn=this.getConn();
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
} catch (SQLException e) {
logger.error("执行查询语句"+sql+"出错:",e);
}
return rs;
}
/**
* 更新sql语句
* @param sql
* @return 整数,更新的条数
*/
public int excuteUpdate(String sql){
int result=0;
try {
if(conn==null||conn.isClosed()) conn=this.getConn();
result=conn.createStatement().executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
/**
* 关闭连接
*/
public void closeConn(){
try{
if(rs!=null){
rs.close();
rs=null;
}
if(stmt!=null){
stmt.close();
stmt=null;
}
if(conn!=null){
conn.close();
conn=null;
}
}catch (SQLException e) {
logger.error("关闭数据库连接出错", e);
}
}
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/55633/showart_726109.html |
|