In my struts application I define a data source to an Oracle DB, everything works as it should until there is a communication problem between the application and the DB (broken pip etc�.) When this problem occurred the application encounter several exceptions and the only way to bring it back to working status is restarting it.
When I we used MySQL database we could specify the autoreconnect parameter (i.e jdbc:mysql://MyDBhost/myDB?autoReconnect=true)
However I could not add this parameter to the Oracle connection string.
Is it possible to add a similar flag in the Oracle url, if not what is good approach for initializing the pool once we encounter network problems.
I did manage to make the problem go away, but my fix is not very clean and efficient.
I'm working with an old JDBC version which doesn't provide 'DataSource' connection pooling, so I'm having to use DBConnectionBroker from javaexchange.com to connect to Oracle
This worked fine most of the time, but then DbConnectionBroker started returning dead connections, which cause the above errors when I run queries.
The trick is to detect dead connections before DBConnectionBroker returns them for use. It already has a 'housekeeping thread', which should find these dead connections, and reestablish them. It runs the checks every 20 seconds. Before it called connection.createStatement to see if the connection was still alive, but I found with oracle JDBC this test was not enough. It was allowing createStatement on a connection object which was dead (and destined to cause an error later)
I changed it so that it actually fires a query, to be absolutely sure the connection is alive:
stmt = connPool[i].createStatement(); ResultSet rset = stmt.executeQuery("SELECT SYSDATE FROM DUAL");
Although this must be a pretty fast query for the oracle server to cope with, it also an unnecessary query, which it is firing it every 20 seconds. So this seems like a bit of an ugly inefficient solution. Anyone have any better ideas for detected dead connection objects?