Example of a connection pool)

Source: Internet
Author: User

This connection pool is obtained directly from JIVE and is modified so that the connection parameters are directly set in the program rather than read from the property file.
Usage:
Set your own connection parameters in the loadProperties method of the DbConnectionDefaultPool. java file. Note that you also need to set the storage location of log files in 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"; // 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: tempqingtuoDbLog. log"; // log File Location
// String logPath = "/tmp/qingtuoDbLog. log ";
String connectionTimeout = "0.5"; // periodically clear useless connection intervals (in days)
Then
In your program, you only need to import the package com. qingtuo. db. pool and use it as follows.
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Try {
Con = DbConnectionManager. getConnection ();
// Write your SQL statement here
}
Catch (SQLException sqle ){
Throw sqle;
}
Finally {
Try {
Pstmt. close ();
}
Catch (Exception e ){
E. printStackTrace ();
}
Try {

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.