proxool连接池情况下rowset的使用

王朝java/jsp·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

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;

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航