title: Oracle JDBC Driver loaded in one class not accessible in another class in same package
body: <p>I am working on an EAR application(deployed on WLS 12c) that has a feature to configure and test jdbc connection for Oracle. So, in my jsp page the user selects the driver as oracle.jdbc.OracleDriver, enter the connectionurl, username and password and clicks on testConnection. And on doing this, the applicaiton gives back an error stating java.sql.SQLException: No suitable driver found for<br>
  <code>jdbc:oracle:thin:@XXX-xx:1525/YYYY</code></p>
  
  <p>A little brief of the architecture used in this application :</p>
  
  <p>On application startup, we are referring to an xml that has all the JDBC defaults and try to load all the supported jdbc drivers that are present in that xml. And oracle.jdbc.OracleDriver is also one of them. This registering is done through a util class JDBCUtil.java which has 2 static methods : registerDriver(String driverName) and isDriverRegistered(String driverName).</p>
  
  <p>So, the first time that JDBCUtil.registerDriver("oracle.jdbc.OracleDriver") is called, isDriverRegistered returns false and within registerDriver, we are making a call to class.forName(driverName) to load the driver. </p>
  
  <p>The logic within isDriverRegistered gets an enumeration of all the drivers registered with DriverManager by calling DriverManager.getDrivers and checks if the driverName string passed to it equals driver.getClass.getName. </p>
  
  <p>After the 1st call to JDBCUtil for OracleDriver, any subsequent calls to registerDriver for OracleDriver is expected to skip the class.forName because the isDriverRegistered is expected to return true. But upon adding logs statement and debugging, i noticed that everytime registerDriver->isDriverRegistered is called for OracleDriver, it is always returning false. The enumearation obtained by calling DriverManager getDrivers, never contains OracleDriver.</p>
  
  <p>Secondly, In another class JDBCDS.java, we are calling JDBCUtil.registerDriver("oracle.jdbc.OracleDriver") and as expected, in registerDriver function exceute Class.forName("oracle.jdbc.OracleDriver") because isDriverRegistered returns false . In JDBCDS.java, after the call to registerDriver, we call DriverManager.getConnection by passing in the url,usename and password. And this call is throwing SQLException saying NoSuitableDriverFound.</p>
  
  <p>So, as another debug test, i called Class.forName("oracle.jdbc.OracleDriver") in JDBCDS.java and then made a call to DriverManager.getConnection and this time i was able to get a connection successfully.</p>
  
  <p>I have gone through all the question related to NoSuitableDriverFound exception on this forum, but nothing is fitting my issue.</p>
  
  <p>I have tried to call create a new instanc of the driver by calling new oracle.jdbc.OracleDriver() within JDBCDS.java and see if it accepts my url and it does. Moreover, this has also ruled out any classpath problem. The jar is certainly in the classpath. Our classpath includes the following:<br>
  <code>com.oracle.db.jdbc7-dms.jar</code> and also weblogic.jar</p>
  
  <p><code>com.oracle.db.jdbc7-dms.jar</code> internally has a link to ojdbc8dms.jar and weblogic.jar internally has ojdbc8.jar included through the Class-Path attribute of its MANIFEST.MF files in both the cases.</p>
  
  <p>Also, this issue is isolated to only a particular environment. In other environments with the same setup, everything works fine without issues.</p>
  
  <p>From JDBCUtil.java :   </p>
  
  <p>static Util Method that is used to register the driver :</p>
  
  <pre><code>public static void registerDriver(String driverName)
  {
      // Calls isDriverRegistered,isDriverRegistered returns false, then call Class.forName(driverName)
  }
  </code></pre>
  
  <p>static method to see if driver is alreay registered :               </p>
  
  <pre><code>public static boolean isDriverRegistered(String driverName)
  {
      //call DriverManager.getDrivers to get all the registered drivers
      if(driver.getClass().getName().equals(driverName))
      {
          return true;  
      }
      return false;
  }
  </code></pre>
  
  <p>Code in JDBCDS.java that is used to perform the test connection:</p>
  
  <pre><code>try {
      JDBCUtil.registerDriver(driver);
      DriverManager.setLoginTimeout(300);
      conn = DriverManager.getConnection(url, username, password); //This code throws No Suitable Driver Found Exception
  } catch (SQLException e) { 
      // tried the below as a test
  
      try
      {
          Class.forName(driver);
      }
      catch(Exception ex)
      {
          Logger.log("Could not load the driver with the current classloader", 4);
          throw e;
      }
      conn = DriverManager.getConnection(url, username, password);//At this step the connection is successfully obtained
  }
  </code></pre>
  
  <p>Both JDBCUtil.java and JDBCDS.java are in the same package.</p>
  
  <p>Can anybody point me towards what i can do further to resolve this issue?</p>