You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "James A. Cubeta" <jc...@gmail.com> on 2006/12/08 22:08:59 UTC

[DBCP] Newbie seeking basic guidance...

Hello DBCP'ers,

I am just starting to use DBCP to create a connection pool for a
application I am writing. I have a few very basic questions - mostly
simple design stuff - that I'd like to pose, but only if these have
not been already addressed elsewhere.

If there are good "101"-level documents for DBCP on the 'net, pointers
would be greatly appreciated. Otherwise, if no one minds the simple
questions, I'll post them here.

Thanks in advance.

James

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


Re: [DBCP] Newbie seeking basic guidance...

Posted by "james a. cubeta" <ja...@cubeta.net>.
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 <dn...@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 <bo...@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


Re: [DBCP] Newbie seeking basic guidance...

Posted by dn...@geovelocity.com.
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 <bo...@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
>
>

Re: [DBCP] Newbie seeking basic guidance...

Posted by "james a. cubeta" <ja...@cubeta.net>.
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 <bo...@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


Re: [DBCP] Newbie seeking basic guidance...

Posted by Bob Arnott <bo...@autonomy.com>.
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


Re: [DBCP] Newbie seeking basic guidance...

Posted by "James A. Cubeta" <jc...@gmail.com>.
Xanana,

Thanks for writing me back, and thanks for the links. I actually did
find these last week, but didn't really study them. I'll take a harder
look at them.

I am the lead developer on a custom server project that does read-only
queries from a database and delivers them to a visualization
application. The whole goal of our software is scale and speed -
queries need to be as fast as possible, and the server must be able to
deliver massive amounts of data.

I initially developed a database conduit using Hibernate, only because
someone else gave me an example and I followed it (I've never been a
hardcore DB programmer). Hibernate certainly makes coding much easier.
However, I started writing some applications to compare the speed of
Hibernate to pure JDBC, and in instances where I need to scale up,
JDBC is much faster (about 50% faster!).

My server is quite multithreaded, and I don't want to set up & tear
down DB connections all the time, so a connection pool is obviously
required. I downloaded DBCP and got a very simple example going.
However, when I incorporated it into my multithreaded tests,
performance drops.

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?

Sorry if this is still "squishy", but I'm still trying to wrap my head
around this myself. I'll do some more reading and I'll get back with
you.

Thanks for offering your help! I really appreciate it!
James


On 12/13/06, Xanana Gusmao <gm...@spamgourmet.com> wrote:
> James,
>
> > If there are good "101"-level documents for DBCP on the 'net, pointers
> > would be greatly appreciated. Otherwise, if no one minds the simple
> > questions, I'll post them here.
>
> I'm a newbie user to DBCP as well.
>
> I've managed to get it working after trawling the net.
>
> These diagrams were very useful for me.
>
> http://jakarta.apache.org/commons/dbcp/guide/classdiagrams.html
> http://jakarta.apache.org/commons/dbcp/guide/sequencediagrams.html
>
> What questions do you have?
>
> Regards,
>
> Xanana
>
>
>
> ---------------------------------------------------------------------
> 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


Re: [DBCP] Newbie seeking basic guidance...

Posted by Xanana Gusmao <gm...@spamgourmet.com>.
James,

> If there are good "101"-level documents for DBCP on the 'net, pointers
> would be greatly appreciated. Otherwise, if no one minds the simple
> questions, I'll post them here.

I'm a newbie user to DBCP as well. 

I've managed to get it working after trawling the net.

These diagrams were very useful for me.

http://jakarta.apache.org/commons/dbcp/guide/classdiagrams.html
http://jakarta.apache.org/commons/dbcp/guide/sequencediagrams.html

What questions do you have?

Regards,

Xanana



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