This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Recovery from a lost database connection

Feb 11th, 2005, 05:38 PM

I am developing database code which will run on a Oracle 10g RAC. Someone has asked if its possible for the Spring jdbc classes to recover when a node in a RAC goes down, such that the connection is reastablished and then all the statement creation is rerun and the statement is reexecuted automatically without having to write application level code. Right now we have code in various places of our non-Spring JDBC code which doesn't handle it in a generic fashion.

I am particularly concerned about being to able to reregistering TypeMaps for the newly recreated Connection.

try &#123;
doThingsWithSpringJdbc&#40;&#41;;
&#125;
catch &#40;CannotGetJdbcConnectionException ex&#41; &#123;
// recover here
// you should be able to use Spring JDBC again, as it should try
// to obtain another connection from the DataSource
&#125;

Comment

If you are using a connection pool, then this would be the responibility of the connection pool implementation. Each operation in the spring data access layer obtains a connection from the pool and returns it when the operation completes, so unless the connection pool cooperates, you might not be able to control the connections from your application code.

Either create a custom class which wraps each of these operations in a try/catch logic and reexecute the command when certain exceptions are thrown, or use Spring AOP to inject the proper code into the existing JdbcTemplate class.

What do people think?

Comment

Interesting... We're also running on Oracle 10g RAC and my boss would
really like such a feature, although I am quite sceptic.
I think we're never gonna use it in reality and it will complicate things.
But please, let us know your experience.