Database Connection Pooling in Tomcat
from http://sukumarvaddi.wordpress.com/2010/05/28/database-connection-pooling-in-tomcat/
1. Open context.xml file, either in/conf or in META-INF folder of the web application for which you want to enable database connection pooling. If you do not have one in META-INF directory, create one and copy the contents of the context.xml in /conf. “Jdbc/myDB” My connection Pooling Jdbc/myDB javax.sql.DataSource Container
Database Connection Pooling in Tomcat
May 28, 2010
1. Open context.xml file, either in
2. Copy the following and paste with in the element. I have it for oracle10g database. You can modify it to suit your database. The following configuration takes care of resource leaks when you forget closing connections or result sets or so.
Connection Pooling will not work for databases with out password.
auth=“Container”
type=“javax.sql.DataSource”
driverClassName=“oracle.jdbc.driver.OracleDriver”
url=“your database Connection URL “
username=“database user name“
password=“database password“ maxActive=“20″ maxIdle=“10″
maxWait=“-1″
removeAbandoned=“true”
removeAbandonedTimeout=“60″/>
3. Copy the following and paste it in web.xml of your
web application
4. Code some thing like following to get the Connection
public Connection getMyDBConnection() {
Connection connection =null;
try{
Context initCTX = new InitialContext();
Context envCtx = (Context) initCTX.lookup(“Jdbc/myDB “);
DataSource ds = (DataSource)envCtx.lookup(“Jdbc/QCToolDB”);
connection = ds.getConnection();
}catch(Exception e){
e.printStackTrace();
}
return connection;
}
댓글