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. getlogger (rowsetfactory. Class. getname ());
Static
{
Try
{
// 1) if the connection pool is not used, use this
// Class. forname ("com. MySQL. JDBC. Driver ");
// 2) proxool connection pool
Class. forname ("org. logicalcobwebs. proxool. proxooldriver ");
} Catch (exception E)
{
Logger. Severe (E. getlocalizedmessage ());
}
}
Public static cachedrowsetimpl getrowset ()
{
Try
{
// 1) if the connection pool is not used, use this
// Connection cannot be released
Cachedrowsetimpl rowset = new cachedrowsetimpl ();
Rowset. seturl ("JDBC: mysql: // 172.18.6.7: 3306/wapchannel? Useunicode = true & amp; characterencoding = gb2312 ");
Rowset. setusername ("root ");
Rowset. setpassword ("");
// 2) when the proxool connection pool is used
// With this method, the default 15 connectioncount will soon be used up
// Rowset. seturl ("proxool. Test: COM. MySQL. JDBC. DRIVER: JDBC: mysql: // 172.18.6.7: 3306/wapchannel? User = root & amp; Password =; & amp; useunicode = true & amp; characterencoding = gb2312 ");
Rowset. setcommand ("select fshortening, ftitle, fparent where fen_topic = ''");
Rowset.exe cute ();
Return rowset;
}
Catch (exception E)
{
Logger. Severe ("error happen when connect to the database 16.27 ");
Return NULL;
}
}
/**
* Correct usage
* @ 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 & amp; Password =; & amp; useunicode = true & amp; characterencoding = gb2312 ";
Properties info = new properties ();
Info. setproperty ("proxool. Maximum-connection-count", "300 ");
Conn = drivermanager. getconnection (URL, Info );
Stmt = conn. createstatement ();
Rset = stmt.exe cutequery (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;
}
}