Example of a connection pool (description)

Source: Internet
Author: User
Tags connection pooling log mysql
The connection pool was removed directly from the jive and modified to allow the connection parameters to be read directly in the program rather than in the subordinate file.

Usage:
First set your own connection parameters, in the Dbconnectiondefaultpool.java file Loadproperties method. Note that you also need to set the location of the log file for the connection pool.

String driver= "Org.gjt.mm.mysql.Driver";//This is the JDBC driver used
String server= "Jdbc:mysql://192.100.100.1/qingtuo";/the URL used
String server= "Jdbc:mysql://192.168.0.1/qingtuo";
String username= "Qingtuo";
String password= "Qingtuo";
String minconnections= "3";//minimum number of connections
String maxconnections= "20";//maximum number of connections
String logpath= "C:\\temp\\qingtuodblog.log";//log file location
String logpath= "/tmp/qingtuodblog.log";
String connectiontimeout= "0.5";//timed purge unwanted connection interval (in days)

and then
In your program you just need to import the package Com.qingtuo.db.pool, and then use the following.

Connection con = null;
PreparedStatement pstmt = null;
ResultSet Rs=null;
try {
con = dbconnectionmanager.getconnection ();
Here to write your SQL statement
}
catch (SQLException Sqle) {
Throw Sqle;
}
finally {
try {
Pstmt.close ();
}
catch (Exception e) {
E.printstacktrace ();
}
try {
Con.close ();
}
catch (Exception e) {
E.printstacktrace ();
}
}

Advantages
Although many application servers also have connection pooling, the benefit of doing so is more generic.

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.