This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to retry Oracle db connection with different server?

 
Ben Hen
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 servers - a primary and a backup. When the first connection fails, how can I get it to try the second server?
dbServer1 = "server1";
dbServer2 = "server2";

My connection:



I've tried if (conn == null) but it doesn't work.

Thanks!
 
Stefan Evans
Bartender
Posts: 1640
9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well there are a couple of scenarios
1 - Connection cannot be established and it throws a SQLException. You need to catch that exception, and then "handle" it by trying the fallback server.


2 - Connection succeeds. Taking a look at the API for java.sql.Connection maybe as well as the test for null, you could try connection.isValid() ?

This sort of logic might be better encapsulated in a java class, or even a JDBC DataSource.
The standard approach in most java apps these days is to use a JNDI Datasource to get connections from rather than the DriverManager.



 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic