Re: Connection Pooling
- From: Alfred <user@xxxxxxxxxxx>
- Date: Tue, 03 Jun 2008 06:41:08 +0200
Chase Preuninger wrote:
What is the best way to create/get a database pool for a serious web
application?
Because of WEB Application a simple sample for Tomcat.
1.Declare Datasource in your Context.xml, e.g.:
<Resource name="MyDatabase"
auth="Container" type="javax.sql.DataSource"
maxActive="10" maxIdle="30" maxWait="10000"
username="sa"
password=""
driverClassName="org.h2.Driver"
url="jdbc:h2:tcp://localhost:9092/hibernate" />
2.Add a resource-ref to your web.xml:
<resource-ref>
<res-ref-name>MyDatabase</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Tomcat build connection pool by themself. Look for
file tomcat-dbcp.jar in Tomcats lib-directory.
3.Get the connection:
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(
"java:comp/env/MyDatabase");
Connection con = ds.getConnection();
4.Close the connection _every_time_ in your SQL source
within _finally_block_. It does not close the connection
but put it back into the pool.
Alfred
.
- Prev by Date: Re: EJB/CMP entity bean question
- Next by Date: Re: EJB/CMP entity bean question
- Previous by thread: Re: EJB/CMP entity bean question
- Next by thread: LDBC driver
- Index(es):
Relevant Pages
|