commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daryl Stultz" <da...@6degrees.com>
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.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