commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "james a. cubeta" <...@cubeta.net>
Subject Re: [DBCP] Newbie seeking basic guidance...
Date Mon, 18 Dec 2006 16:49:51 GMT
Dave,

Thank you for the code! I am trying to adapt it to my test case here.

So, based on your example, it would seem that my methods should
function as follows:

   public Connection getConn() throws SQLException {
       return dataSource.getConnection();
   }

   public void releaseConn(Connection c) throws SQLException {
      c.close();
   }

How do I close the dataSource itself when my application terminates?

Thanks again,
James

On 12/15/06, dneufeld@geovelocity.com <dneufeld@geovelocity.com> wrote:
> James,
>
> I started down the same path as you and have since switched to the
> BasicDataSourceFactory implementation which I think is achieving a pooled
> connection.  I have a servlet implementation and connection is defined as
> static.
>
> Attached is the code.
>
> cheers,
> Dave
>
> > Bob, thanks for the reply.
> >
> > I'm not using BasicDataSource at all, but maybe I should? I dunno. I
> > am basing my code off of one of the examples. To create my pool:
> >
> > ObjectPool pool = new GenericObjectPool(null);
> > ConnectionFactory conFactory =
> >           new DriverManagerConnectionFactory(uri, dbUsername, dbPassword);
> > PoolableConnectionFactory factory =
> >           new PoolableConnectionFactory(connFactory, pool, null, null,
> > true, false);
> > Class.forName(driverClassName);
> > Class.forName("org.apache.commons.dbcp.PoolingDriver");
> > PoolingDriver driver = (PoolingDriver)
> > DriverManager.getDriver("jdbc:apache:commons:dbcp:");
> > driver.registerPool("myPool", pool);
> >
> > To use a connection:
> >
> >    public Connection getConn() throws SQLException {
> >       return
> > DrvierManager.getConnection("jdbc:apache:commons:dbcp:myPool");
> >    }
> >
> > To return a connection:
> >
> >    public void releaseConn(Connection c) throws SQLException {
> >       c.close();
> >    }
> >
> > Perhaps I'm going about this all wrong?
> >
> > James
> >
> >
> >
> >
> > On 12/13/06, Bob Arnott <boba@autonomy.com> wrote:
> >> James A. Cubeta wrote:
> >>
> >> [snipped...]
> >>
> >> > So my questions revolve around tweaking this framework for speed. I
> >> > guess my very first question is: Is there a way to instruct DBCP to
> >> > initially set up a some number of connections?
> >>
> >> When you create your pool with BasicDataSource, you can modify its
> >> behavior
> >> with it's properties. One of them is initialSize -
> >>
> >> http://jakarta.apache.org/commons/dbcp/apidocs/org/apache/commons/dbcp/BasicDataSource.html#initialSize
> >>
> >> Perhaps this will supply the functionality you are looking for...?
> >>
> >> Cheers,
> >>
> >> --
> >> Bob Arnott
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >>
> >>
> >
> >
> > --
> > James A. Cubeta
> > 703.624.5689 (c) / 571.223.3368 (w)
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>


-- 
James A. Cubeta
703.624.5689 (c) / 571.223.3368 (w)

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message