title: Java connecting to Oracle Grid - DB connection string
body: <p><strong>This is DB connection string to Oracle</strong></p>
  
  <pre><code>ABCSERVICE =
   (DESCRIPTION =
  (ADDRESS = (PROTOCOL = TCP)(HOST = servername1-vip.test.ampf.com)(PORT = 1521))
  (ADDRESS = (PROTOCOL = TCP)(HOST = servername2-vip.test.ampf.com)(PORT = 1521))
  (ADDRESS = (PROTOCOL = TCP)(HOST = servername3-vip.test.ampf.com)(PORT = 1521))
  (LOAD_BALANCE = yes)
  (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = ABCSERVICE)
  )
  )
  </code></pre>
  
  <p>I used one of the server and the conenction is working. I need help in having the connection string done for the above Oracle grid
  one so that if there is fail over the next server is picked up</p>
  
  <p><strong>Connection string for one server</strong></p>
  
  <p>jdbc:oracle:thin:@//servername1-vip.test.ampf.com/ABCSERVICE</p>
  
  <p><strong>Program for Single Server</strong></p>
  
  <pre><code>import java.sql.*;
  import java.util.ArrayList;
  import java.util.List;
  
  public class DBConnection {
  
  public static void executeQuery(final Connection connection) throws SQLException
    {
        try{
  
              // test the conenction here and it works
  
              }
  
          }catch (SQLException e) {
              System.out.println(e);
          }
    }
  
  
  
  public static void main(final String[] args) throws Exception{
  
  Connection connection = null;
  try {
      // Load the JDBC driver
      String driverName = "oracle.jdbc.driver.OracleDriver";
      Class.forName(driverName);
  
      // Create a connection to the database
      String serverName = "servername1-vip.test.ampf.com";
      String portNumber = "1521";
      String serviceName = "ABCSERVICE";
  
      String url = "jdbc:oracle:thin:@//" + serverName + ":" + portNumber + "/" + serviceName;
      System.out.println(url);
      String username = "userName";
      String password = "passWord";
      connection = DriverManager.getConnection(url, username, password);
  
      executeQuery(connection);
  } catch (ClassNotFoundException e) {
      System.out.println(e);
  } catch (SQLException e) {
      // Could not connect to the database
      System.out.println(e);
  }
  
  }
       }
  </code></pre>