public class ConnectionFailoverExample { publicstaticvoid main(String[] args) { // Assume using JDBC 4.0 driver on JVM 6+. No driver loading needed. Properties myProp = new Properties(); myProp.put("user", "dbadmin"); myProp.put("password", "vertica"); // Set two backup hosts to be used if connecting to the first host // fails. All of these hosts will be tried in order until the connection // succeeds or all of the connections fail. myProp.put("BackupServerNode", "VerticaHost02,VerticaHost03"); Connection conn; try { // The connection string is set to try to connect to a known // bnad host (in this case, a host that never existed). conn = DriverManager.getConnection( "jdbc:vertica://BadVerticaHost:5433/vmart", myProp); System.out.println("Connected!"); // Query system to table to see what node we are connected to. // Assume a single row in response set. Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery( "SELECT node_name FROM v_monitor.current_session;"); rs.next(); System.out.println("Connected to node " + rs.getString(1).trim()); // Done with connection. conn.close(); } catch (SQLException e) { // Catch-all for other exceptions e.printStackTrace(); } } }