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.
subject: How to retry Oracle db connection with different server?