commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Blashill" <JBlash...@rim.com>
Subject [DBCP + DBUTILS] DBCP testOnBorrow feature not working.. :(
Date Wed, 20 Oct 2004 21:11:20 GMT
hello,

I'm wondering if anyone might have some inclination as to why the
testOnBorrow feature would work when I'm doing straight JDBC vs using
DBUtils?

Here is my code for using the datasource:

JDBC

    Connection conn = dataSource.getConnection();
    PreparedStatement ps = conn.prepareStatement("select count(*) from
dbinfo;");
    ResultSet rs = ps.executeQuery();
    rs.next();
    long count = rs.getLong(1);
    ...

DbUtils

    QueryRunner queryRunner = new QueryRunner(dataSource);
    Long count = (Long)queryRunner.query("select count(*) from dbinfo;",
new ScalarHandler());
    ....

Here is my code for creating a datasource:

    ObjectPool connectionPool = new GenericObjectPool(null,
genericObjectPoolConfig*); 
    ConnectionFactory connectionFactory = new
DriverManagerConnectionFactory(connectString, user, password);
    KeyedObjectPoolFactory keyedObjectPoolFactory = new
GenericKeyedObjectPoolFactory(null, genericKeyedObjectPoolConfig);
    PoolableConnectionFactory poolableConnectionFactory = new
PoolableConnectionFactory(connectionFactory, 
					connectionPool,
keyedObjectPoolFactory, "select count(*) from dbinfo;", false, true);
    PoolingDataSource dataSource = new
PoolingDataSource(connectionPool);

* where genericObjectPoolConfig.testOnBorrow = true

The result is that the JDBC version weeds out connections that have
'gone bad' and recovers, whereas the DbUtils code does not.

Am I wrong in assuming that my DBCP DataSource was created correctly
because the JDBC code works correctly?

Any thoughts would be much appreciated!!

Thanks,

James



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