commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dirk Verbeeck <dirk.verbe...@pandora.be>
Subject Re: DBCP general setup and use
Date Thu, 02 Oct 2003 22:32:41 GMT
Hi Daryl,

There is a preview website of the v1.1 version you will find more info 
about the various parameters:
http://cvs.apache.org/~dirkv/dbcp/configuration.html

Constructing your own datasource can be a bit tricky, take a look at 
BasicDataSource as example
http://cvs.apache.org/viewcvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSource.java

You might also want to look at the Developers guide:
http://cvs.apache.org/~dirkv/dbcp/guide/classdiagrams.html

The official website will be updated in a couple of days, then you will 
find all the info there as well.

A few pointers about your current code:
The properties you give to the DriverManagerConnectionFactory are the 
properties for your database driver.
In your case only "user" & "password".
The driver itself should be loaded by a Class.forName(driver); as you 
would do without a pool.
The other settings you have to do using the setters on config, 
connectionPool and dataSource.

Mapping of your old configuration:
* max connections - the maximum number of connections allowed out
=> connectionPool maxActive
* min connections - the number of connections to open upon start up
=> minIdle   (not only at startup but always) (needs 
timeBetweenEvictionRunsMillis configuration)
* max checkout - the number of seconds a connection is allowed out of 
the pool
=> AbandonedConfig removeAbandonedTimeout
* connection reset time - a possibly DbConnectionBroker-specific recycle 
time (defaults to one day)
=> connectionPool minEvictableIdleTimeMillis (needs 
timeBetweenEvictionRunsMillis configuration)

When you create a "PoolableConnectionFactory" it registers itself on the 
"connectionPool" using the setFactory method
so you just need to create one at make it all work.

Be sure to use the v1.1 release candidate:
http://cvs.apache.org/~dirkv/builds/

Documentation improvements are welcome, there is still room for 
improvement ;-)

Cheers
Dirk


Daryl Stultz wrote:

> Hi Folks,
> I'm trying to convert my database handling from DbConnectionBroker to 
> DBCP.
> Here is my code for creating datasources. I'm a bit unsure how to
> configure the whole thing - the docs are a bit weak.
>
> AbandonedConfig config = new AbandonedConfig();
> config.setLogAbandoned(true);
> config.setRemoveAbandoned(true);
> config.setRemoveAbandonedTimeout((new Double(maxConnTime)).intValue());
>
> ObjectPool connectionPool = new GenericObjectPool(null);
>
> Properties props = new Properties();
> Object drivObj = Class.forName(driver);
> props.setProperty("driverClassName", driver);
> props.setProperty("driverName", driver);
> props.setProperty("user", login);
> props.setProperty("password", password);
> props.setProperty("maxActive", Integer.toString(maxConn));
> props.setProperty("maxIdle", Integer.toString(minConn));
> props.setProperty("maxWait", Integer.toString(maxCheckout));
>
> ConnectionFactory connectionFactory = new
> DriverManagerConnectionFactory(server, props);
> PoolableConnectionFactory poolableConnectionFactory = new
> PoolableConnectionFactory(connectionFactory, connectionPool, null, null,
> false, true, config);
>
> PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
>
>
> I don't really understand the three properties on AbandonedConfig. I also
> can't find any official description of the various properties I am setting
> here (props). Basically my current config files specify:
>
> driver - the class name
> server - the connection string
> user
> password
> max connections - the maximum number of connections allowed out
> min connections - the number of connections to open upon start up
> max checkout - the number of seconds a connection is allowed out of the
> pool
> connection reset time - a possibly DbConnectionBroker-specific recycle
> time (defaults to one day)
>
> Aside from the first four, I'm not exactly sure where the others plug in.
> maxActive seems to map to my max connections. Does maxIdle map to min
> connections? What is maxWait?
>
> How do I set up logging? Can I specify a file to log to? Append or
> overwrite? A log level? I can't get myself to trust this pooler if I can't
> monitor it.
>
> The examples (including mine) all spin up an instance of
> PoolableConnectionFactory but then don't use it. If I take it out, it
> doesn't work. Is there a side-effect to creating this instance? Why isn't
> a static method? What might I want to do with the instance?
>
> Also, note that I needed to put in the line above
> Object drivObj = Class.forName(driver);
> in order for it to work with Microsoft SQLServer. Any idea why? The
> driverClassName and driverName properties didn't seem to help - it throws
> a "No suitable driver" error without this line.
>
> Thanks for any help.
>
> Daryl Stultz
> _____________________________________
> 6 Degrees Software and Consulting, Inc.
> http://www.6degrees.com
> mailto:daryl@6degrees.com





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