Tips for configuring database connection pooling

Source: Internet
Author: User
Tags connection pooling tomcat server

For enterprise applications with high performance requirements, using JDBC to connect to a database generally does not meet the requirements, it is necessary to use the database connection pool. For connection pooling it should be no stranger, you can learn the basic Java tutorial .

The database connection pool is responsible for allocating, managing, and freeing the database connection, which allows the application to reuse an existing database connection instead of re-establishing a database connection that has been idle for more than the maximum idle time to avoid missing database connections due to the absence of a database connection being freed. This technology can significantly improve the performance of database operations.

two ways to configure database connection pooling

Tomcat Server configuration steps:

1. Paste the following code into the D:\apache-tomcat-6.0.14\conf context.xml to the label pair in the file. (The specific path is subject to actual)

Name= "Jdbc/test"
Auth= "Container"
type= "Javax.sql.DataSource"
maxactive= "20"
maxidel= "10"
maxwait= "1000"
username= "HR"
password= "HR"
driverclassname= "Oracle.jdbc.driver.OracleDriver"
url= "Jdbc:oracle:thin: @localhost: 1521:oracle" >


2. Copy the database drive jar package to the D:\apache-tomcat-6.0.14\lib directory (the specific path is the actual)
3, the original DBHelper class to get the database connection static method to modify the following method
Establish and connect to the database
public static Connection getconnection () {
DataSource ds;
InitialContext CXT;
try {
CXT = new InitialContext ();

ds = (DataSource) cxt.lookup ("Java:/comp/env/jdbc/test");

conn = Ds.getconnection ();

} catch (Exception e) {

E.printstacktrace ();
}
Return conn;
}
Steps to configure in each project:
1. Create a context.xml file in Webroot/meta-inf and copy the contents below to the file
type= "Javax.sql.DataSource"
driverclassname= "Oracle.jdbc.driver.OracleDriver"
url= "Jdbc:oracle:thin: @localhost: 1521:oracle" username= "HR"
password= "hr" maxactive= "maxidle=" "maxwait=" 10000 "/> "
2. Import the database driver jar package into the project
3, the original DBHelper class to get the database connection static method to modify the following method
Establish and connect to the database
public static Connection getconnection () {
try {
InitialContext initcontext = new InitialContext ();
DataSource ds = (DataSource) Context.lookup ("jdbc/oracle");

conn = Ds.getconnection ();
"catch (Exception e) {
E.printstacktrace ();

return conn;

}

These are the two ways to configure the database connection pool, if you want to learn more about programming language Tutorials , Please log in to E-mentor network.

Tips for configuring database connection pooling

Related Article

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.