Use of rowset in proxool connection pool

Source: Internet
Author: User

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;
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.