aspose file tools
The moose likes Servlets and the fly likes How to retry Oracle db connection with different server? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "How to retry Oracle db connection with different server?" Watch "How to retry Oracle db connection with different server?" New topic
Author

How to retry Oracle db connection with different server?

Ben Hen
Greenhorn

Joined: Mar 27, 2012
Posts: 5
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

Joined: Jul 06, 2005
Posts: 1005
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to retry Oracle db connection with different server?
 
Similar Threads
close sql connection in finally block
Savepoints and transactions
How To Access Objects Returned From A Helper/Utility Class?
how to give the real connection back to the pool
Connection Leaks