proxool连接池情况下rowset的使用

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import java.util.logging.Logger;

import javax.sql.rowset.CachedRowSet;
import com.sun.rowset.CachedRowSetImpl;

public class RowSetFactory
{
private static Logger logger=Logger.getLogger(RowSetFactory.class.getName());
static
{
try
{
//1)非连接池情况下,用这个
//Class.forName("com.mysql.jdbc.Driver");
//2)proxool连接池
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
}catch(Exception e)
{
logger.severe(e.getLocalizedMessage());
}
}
public static CachedRowSetImpl getRowSet()
{
try
{
//1)非连接池情况下,用这个
//connection不能够释放
CachedRowSetImpl rowSet=new CachedRowSetImpl();
rowSet.setUrl("jdbc:mysql://172.18.6.7:3306/wapchannel?useUnicode=true&characterEncoding=gb2312");
rowSet.setUsername("root");
rowSet.setPassword("");
//2)proxool连接池情况下,用这个
//用这个方法,默认的15个connectionCount很快就用完了
//rowSet.setUrl("proxool.test:com.mysql.jdbc.Driver:jdbc:mysql://172.18.6.7:3306/wapchannel?user=root&password=;&useUnicode=true&characterEncoding=gb2312");

rowSet.setCommand("select Fshortening,Ftitle,Fparent where Fen_topic=''");
rowSet.execute();
return rowSet;
}
catch(Exception e)
{
logger.severe("error happen when connect to the database 16.27");
return null;
}
}
/**
* 正确的使用方法
* @param sql
* @return
*/
public static CachedRowSet query(String sql){
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
try {
CachedRowSetImpl rs= new CachedRowSetImpl();
String url = "proxool.test:com.mysql.jdbc.Driver:jdbc:mysql://172.23.2.3:3306/wapchannel?user=root&password=;&useUnicode=true&characterEncoding=gb2312";
Properties info= new Properties();
info.setProperty("proxool.maximum-connection-count", "300");
conn=DriverManager.getConnection(url,info);
stmt = conn.createStatement();
rset = stmt.executeQuery(sql);
rs.populate(rset);
return rs;
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (stmt != null)
stmt.close();
} catch (Exception e) {
}
try {
conn.close();
} catch (Exception e) {
}
conn = null;
stmt = null;
rset = null;
}
return null;
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值