commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daryl Stultz" <>
Subject DBCP general setup and use
Date Thu, 02 Oct 2003 19:51:29 GMT
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.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
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
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.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message