You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Scott Purcell <sp...@vertisinc.com> on 2005/04/12 20:33:46 UTC

DBCP Pooled?

Thanks Dirk,

So now I decided to use the JNDI, and I have a BasicDataSource object in a class. What are the steps, or what is required (or link) to start using pooled connections?

Is the BasicDataSource a pool of connections, or just a single connection? How can one use this from the standpoint of some type of singleton that could hand out connections when asked for.


Thanks,
Scott

-----Original Message-----
From: Dirk Verbeeck [mailto:dirk.verbeeck@pandora.be]
Sent: Tuesday, April 12, 2005 1:21 AM
To: Jakarta Commons Users List
Subject: Re: DBCP Getting started


JNDI is a naming service, a kind of tree/map between a JNDI name and a 
service object.
Tomcat uses the BasicDataSourceFactory to create a BasicDataSource 
from your configuration settings.
http://jakarta.apache.org/commons/dbcp/xref/org/apache/commons/dbcp/BasicDataSourceFactory.html

There is no functional difference between the DBCP datasource tomcat 
creates or one you would create. Either method works.
Its a matter of preference. If you use JNDI and deploy your 
application on lets say a BEA weblogic platform then you would start 
using their datasource, if you create a BasicDataSource yourself then 
you always know it is the DBCP implementation.

-- Dirk

Scott Purcell wrote:

> I am having trouble understanding how the DBCP classes work within Tomcat.
> 
> I have been on the Tomcat site for the past two days, trying to figure things out. I have been following their example of how to create a the <Context /> and a <Resource /> and pull those our using JNDI? in order to use obtain a "DataSource".
> 
> But now after spending some time on the DBCP site, and checking the examples, I do not see why I need to even use JNDI at all.
> 
> I am looking at a example here: 
> http://cvs.apache.org/viewcvs.cgi/jakarta-commons/dbcp/doc/BasicDataSourceExample.java?view=markup
> 
> And it just shows using the pool without all the JNDI connection, etc.
> 
> 
> Can someone try and explain to me how this fits together, and why Tomcats example of using DBCP differs from this sites?
> 
> Thanks,
> Scott



---------------------------------------------------------------------
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


Re: DBCP Pooled?

Posted by Dirk Verbeeck <di...@pandora.be>.
BasicDataSource is a thread-safe pooling DataSource.
No extra steps are required. Once you have your datasource you can do 
getConnection/close without extra synchronization and you will get a 
pooled connection.

By the way, can you please write down these questions/answers into the 
wiki (dbcp FAQ). This mailing is the best way for asking questions but 
it would be nice if you can write down your new knowledge into the 
wiki to help other users.

-- Dirk

Scott Purcell wrote:

> Thanks Dirk,
> 
> So now I decided to use the JNDI, and I have a BasicDataSource object in a class. What are the steps, or what is required (or link) to start using pooled connections?
> 
> Is the BasicDataSource a pool of connections, or just a single connection? How can one use this from the standpoint of some type of singleton that could hand out connections when asked for.
> 
> 
> Thanks,
> Scott
> 
> -----Original Message-----
> From: Dirk Verbeeck [mailto:dirk.verbeeck@pandora.be]
> Sent: Tuesday, April 12, 2005 1:21 AM
> To: Jakarta Commons Users List
> Subject: Re: DBCP Getting started
> 
> 
> JNDI is a naming service, a kind of tree/map between a JNDI name and a 
> service object.
> Tomcat uses the BasicDataSourceFactory to create a BasicDataSource 
> from your configuration settings.
> http://jakarta.apache.org/commons/dbcp/xref/org/apache/commons/dbcp/BasicDataSourceFactory.html
> 
> There is no functional difference between the DBCP datasource tomcat 
> creates or one you would create. Either method works.
> Its a matter of preference. If you use JNDI and deploy your 
> application on lets say a BEA weblogic platform then you would start 
> using their datasource, if you create a BasicDataSource yourself then 
> you always know it is the DBCP implementation.
> 
> -- Dirk
> 
> Scott Purcell wrote:
> 
> 
>>I am having trouble understanding how the DBCP classes work within Tomcat.
>>
>>I have been on the Tomcat site for the past two days, trying to figure things out. I have been following their example of how to create a the <Context /> and a <Resource /> and pull those our using JNDI? in order to use obtain a "DataSource".
>>
>>But now after spending some time on the DBCP site, and checking the examples, I do not see why I need to even use JNDI at all.
>>
>>I am looking at a example here: 
>>http://cvs.apache.org/viewcvs.cgi/jakarta-commons/dbcp/doc/BasicDataSourceExample.java?view=markup
>>
>>And it just shows using the pool without all the JNDI connection, etc.
>>
>>
>>Can someone try and explain to me how this fits together, and why Tomcats example of using DBCP differs from this sites?
>>
>>Thanks,
>>Scott



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