Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.databases > #158

Re: Connection Pooling

From "Alfred" <alfred@THRWHITE.remove-dii-this>
Subject Re: Connection Pooling
Message-ID <4844cb62$1_1@news.bluewin.ch> (permalink)
Newsgroups comp.lang.java.databases
References <c4cccce5-398e-40e2-9c0e-d347336e6b26@a70g2000hsh.googlegroups.com>
Date 2011-04-27 15:22 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.databases
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

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.databases | Previous | NextPrevious in thread | Find similar


Thread

Connection Pooling "Chase Preuninger" <chase.preuninger@THRWHITE.remove-dii-this> - 2011-04-27 15:21 +0000
  Re: Connection Pooling "=?ISO-8859-1?Q?Arne_Vajh=" <=?iso-8859-1?q?arne_vajh=@THRWHITE.remove-dii-this> - 2011-04-27 15:22 +0000
    Re: Connection Pooling kuassi.mensah@gmail.com.remove-dii-this - 2011-04-27 15:22 +0000
      Re: Connection Pooling "=?ISO-8859-1?Q?Arne_Vajh=" <=?iso-8859-1?q?arne_vajh=@THRWHITE.remove-dii-this> - 2011-04-27 15:22 +0000
        Re: Connection Pooling kuassi.mensah@gmail.com.remove-dii-this - 2011-04-27 15:22 +0000
  Re: Connection Pooling "Alfred" <alfred@THRWHITE.remove-dii-this> - 2011-04-27 15:22 +0000

csiph-web