[dbcp] usage of BasicDataSource

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[dbcp] usage of BasicDataSource

mark archur
Hi,
I configured the dbcp properly and I tested with my prototype and is working fine. what is the purpose of BasicDataSource? How is it different from normal DataSource? Can't I achieve PreparedStatement pooling when I use DataSource?
 
If I want to use BasicDataSource, do we have to set all the settings programatically using setUsername, setPassword, setMaxIdle, setMaxIdle, etc?
 
Thanks for the answers in advance.

               
---------------------------------
Yahoo! Sports
 Rekindle the Rivalries. Sign up for Fantasy Football
Reply | Threaded
Open this post in threaded view
|

Re: [dbcp] usage of BasicDataSource

Dirk Verbeeck
Hi Mark,

mark archur wrote:
> Hi,
> I configured the dbcp properly and I tested with my prototype and is working fine. what is the purpose of BasicDataSource? How is it different from normal DataSource? Can't I achieve PreparedStatement pooling when I use DataSource?

BasicDataSource is an implementation of the Datasource interface. It
support a preparedstatement pooling and other nice features.
If you only use the methods defined in the Datasource interface then you
can replace the dbcp datasource by another implementation so it is a
best practice to use the dbcp methods only when creating the pool and
use the datasource interface in your application code.

> If I want to use BasicDataSource, do we have to set all the settings programatically using setUsername, setPassword, setMaxIdle, setMaxIdle, etc?
The are defaults for most properties. You have of you course set some of
them (username/password, url, ...).
You can also use:
ds = BasicDataSourceFactory.createDataSource(Properties properties);
and configure the pool using a property file.

> Thanks for the answers in advance.

Cheers
Dirk


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [dbcp] usage of BasicDataSource

mark archur
Hi Dirk/All,
 
Thanks for the information on BasicDataSource. Its good to know that BasicDataSource can give me all I want. Though, I do not seem to run out of questions yet related to dbcp:).......
 
Regarding setting parameters via setter methods: I defined these settings in my server.xml and the code seems to be picking up/honoring these settings. Are setter methods of BasicDataSource not another way of setting parameters to the pool? What is the right way and/or the usual way of setting these parameters? via server.xml? or via setter methods of BasicDataSource?
 
Similarly, regarding setting connectionProprties to the driver, there is a parameter "connectionParameters" which can be defined in server.xml ans can be used to set different driver proprties. Do we still have to do this via BasicDataSource.setConnectionProperties() method?
 
I read at few places (eg: dbcp tool java doc) that *abandoned* is deprepcated and will be removed from the future releases. Is this deprecation valid/true only for BasicDataSource.*Abandoned*() methods? or is it valid even with setting *abandoned* parameters in server.xml? finally, is it not advisable to use *abandoned* related stuff now when usinf commons-dbcp-1.1 version?
 
Thanks in advance for the answers.

Dirk Verbeeck <[hidden email]> wrote:
Hi Mark,

mark archur wrote:
> Hi,
> I configured the dbcp properly and I tested with my prototype and is working fine. what is the purpose of BasicDataSource? How is it different from normal DataSource? Can't I achieve PreparedStatement pooling when I use DataSource?

BasicDataSource is an implementation of the Datasource interface. It
support a preparedstatement pooling and other nice features.
If you only use the methods defined in the Datasource interface then you
can replace the dbcp datasource by another implementation so it is a
best practice to use the dbcp methods only when creating the pool and
use the datasource interface in your application code.

> If I want to use BasicDataSource, do we have to set all the settings programatically using setUsername, setPassword, setMaxIdle, setMaxIdle, etc?
The are defaults for most properties. You have of you course set some of
them (username/password, url, ...).
You can also use:
ds = BasicDataSourceFactory.createDataSource(Properties properties);
and configure the pool using a property file.

> Thanks for the answers in advance.

Cheers
Dirk


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 
Reply | Threaded
Open this post in threaded view
|

Re: [dbcp] usage of BasicDataSource

Dirk Verbeeck
Answers inline...
mark archur wrote:
> Hi Dirk/All,
>  
> Thanks for the information on BasicDataSource. Its good to know that BasicDataSource can give me all I want. Though, I do not seem to run out of questions yet related to dbcp:).......
>  
> Regarding setting parameters via setter methods: I defined these settings in my server.xml and the code seems to be picking up/honoring these settings. Are setter methods of BasicDataSource not another way of setting parameters to the pool? What is the right way and/or the usual way of setting these parameters? via server.xml? or via setter methods of BasicDataSource?

Yes, defining the settings in server.xml has the same effect as using
the setters on BasicDatasource. Tomcat calls BasicDatasourceFactory with
these server.xml settings and the factory creates a BasicDatasource and
sets the properties.
The preferred way is to configure everything in server.xml.


> Similarly, regarding setting connectionProprties to the driver, there is a parameter "connectionParameters" which can be defined in server.xml ans can be used to set different driver proprties. Do we still have to do this via BasicDataSource.setConnectionProperties() method?

You can use addConnectionProperty(String name, String value) but using
server.xml also works.


> I read at few places (eg: dbcp tool java doc) that *abandoned* is deprepcated and will be removed from the future releases. Is this deprecation valid/true only for BasicDataSource.*Abandoned*() methods? or is it valid even with setting *abandoned* parameters in server.xml? finally, is it not advisable to use *abandoned* related stuff now when usinf commons-dbcp-1.1 version?

The *abandoned* feature has been deprecated since 1.1, in general its
use is still supported but not recommended. The classes are deprecated
because the current implementation and API may change in a future
version. See also:
http://wiki.apache.org/jakarta-commons/DBCP

> Thanks in advance for the answers.

-- Dirk


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]