Hi,
I had some suspicions, if dbcp is executing the validation query. So, I
created an Oracle sequence, and had the validation query increment it.
The sequence is not getting incremented. It's probably a configuration
mistake on my part. Please, take a look at my code:
// set up dbcp
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
ds.setUsername("bla");
ds.setPassword("bla");
ds.setUrl("jdbc:oracle:thin:@bla:1521:bla");
ds.setMaxActive(20);
ds.setMaxIdle(20);
ds.setTestOnBorrow(true);
ds.setTestOnReturn(true);
ds.setTestWhileIdle(true);
ds.setValidationQuery("select tf_dbcp_test.nextval from
dual");
// get connection and return it to simulate some usage
PreparedStatement stmt = conn.prepareStatement("select *
from bla");
ResultSet result = stmt.executeQuery();
result.next();
System.out.println("fly product is " + result.getString(1));
conn.commit();
result.close();
stmt.close();
conn.close();
// get another connection
conn = ds.getConnection();
conn.close();
I'd expect that dbcp would execute the validation query four times (2 *
on borrow and 2 * on return). Though, the sequence has not been
incremented.
Any tips?
Thanks,
Thomas