기본 콘텐츠로 건너뛰기

Database Connection Pooling in Tomcat

from http://sukumarvaddi.wordpress.com/2010/05/28/database-connection-pooling-in-tomcat/



Database Connection Pooling in Tomcat

2 Comments
 
 
Rate This

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.
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.
“Jdbc/myDB”
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
My connection Pooling
Jdbc/myDB
javax.sql.DataSource
Container
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;
}

댓글

이 블로그의 인기 게시물

remove bluebirds.exe , virtual drive

4,5,6 띠 저항의 색띠를 읽는 법(띠저항 값)

수지에서 인천공항 리무진 버스 (인천공항버스정보)(2022년3월업데이트)