strategy for jdbc connection errors
Hi
Anybody got any best practices for how to deal with connection problems
in JDBC with commons DBCP/Pool?
I am working on a storage tier where the DAOs can encounter faulty
database connections, either closed or other-wise non functional
connections. The database connection is pooled with Commons DBCP/Pool
and my initial thought was to reinitialise or restart the pool, if any
problems are encountered of that sort..
I then realised that the pool can test the connections before leasing it
to the application. This moves me into muddy waters, because I dont know
much about these details and I am having trouble finding decent
documentation on the subject.
My original code is something like:
while (retry > 0) {
Connection con = ds.getConnection();
if (con==null) {
dsFactory.restartDS();
retry--:
continue;
}
try {
dao1.execute();
dao2.execute();
retry=0; // Completed succesfully
} catch (SQLExceptions e) {
if (retry == 0) {
throw new FaultRuntimeException("Failed operation...", e);
retry--:
continue;
}
con.close();
}
Not knowing the details of how the DBCP, DataSource or JDBC works in
these situations, this code is prone to problems.
I will continue to investigate, but any feedback about the details of
DBCP, Pool or what to look at is appreciated.
regards
Jan