Example 6-1: Examples class hides JDBC connection details

import java.sql.*; 
import java.util.*; 
import oracle.jdbc.driver.*; 
 
public class Examples {

  // Return a JDBC Connection appropriately either outside or inside Oracle8i
  public static Connection getConnection() throws SQLException {
    String     username      = "xmlbook";
    String     password      = "xmlbook";
    String     thinConn      = "jdbc:oracle:thin:@localhost:1521:ORCL";
    String     default8iConn = "jdbc:oracle:kprb:";
    Connection cn            = null;
    try {
      // Register the JDBC Driver
      Driver d = new oracle.jdbc.driver.OracleDriver();
      // Connect with the Native (kprb) Driver if inside Oracle8i
      if (insideOracle8i()) {
        cn = DriverManager.getConnection(default8iConn);
      }
      else { // Connect with the Thin Driver
        cn = DriverManager.getConnection(thinConn,username,password);
      }
      // Make sure JDBC Auto-Commit is off.
      cn.setAutoCommit(false);
      return cn;
    }
    catch (Exception e) {throw new SQLException("Error Loading JDBC Driver"); }
  }
  public static boolean insideOracle8i() {
    // If oracle.server.version is non null, we're running in the database
    String ver = System.getProperty("oracle.server.version");
    return (ver != null && !ver.equals(""));
  }
}