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