Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8076639

JDBC driver loading no longer works

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 9
    • core-libs
    • x86
    • linux

      FULL PRODUCT VERSION :
      java version "1.9.0-ea"
      Java(TM) SE Runtime Environment (build 1.9.0-ea-b52)
      Java HotSpot(TM) Server VM (build 1.9.0-ea-b52, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux slpncsprc01 2.6.32-220.7.1.el6.x86_64 #1 SMP Fri Feb 10 15:22:22 EST 2012 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      Applications loading JDBC drivers from the user classpath no longer work.

      REGRESSION. Last worked in version 8u40

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.9.0-ea"
      Java(TM) SE Runtime Environment (build 1.9.0-ea-b52)
      Java HotSpot(TM) Server VM (build 1.9.0-ea-b52, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile the attached code to the current directory
      2. Run with java -cp .:derby.jar:jconn4.jar n
      3. Run with java -cp .:derby.jar:jconn4.jar y

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The application should print the following output for steps 2 and 3, indicating that the correct drivers were found but that the application could not connect to non-existant server/database combinations

      Trying to connect to jdbc:derby:sample
      Database 'sample' not found.
      Trying to connect to jdbc:sybase:Tds:server:4100/test
      JZ006: Caught IOException: java.net.UnknownHostException: server
      ACTUAL -
      When drivers are not preloaded (step 2), the Sybase driver is found but the Derby driver is not.
      When drivers are preloaded (step 3), neither driver is found.

      Step 2:
      Trying to connect to jdbc:derby:sample
      No suitable driver found for jdbc:derby:sample
      Trying to connect to jdbc:sybase:Tds:server:4100/test
      JZ006: Caught IOException: java.net.UnknownHostException: server

      Step 3:
      Class not found: org.apache.derby.jdbc.EmbeddedDriver
      Class not found: org.apache.derby.jdbc.AutoloadedDriver
      Class not found: org.apache.derby.jdbc.AutoloadedDriver40
      Trying to connect to jdbc:derby:sample
      No suitable driver found for jdbc:derby:sample
      Trying to connect to jdbc:sybase:Tds:server:4100/test
      No suitable driver found for jdbc:sybase:Tds:server:4100/test

      Note that the JDK documentation at http://docs.oracle.com/javase/8/docs/api/java/sql/DriverManager.html specifies that applications may preload the driver class with no effect, and the Tomcat documentation at http://tomcat.apache.org/tomcat-8.0-doc/jndi-datasource-examples-howto.html specifies that web applications loading their drivers from WEB-INF/lib MUST preload their classes.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.sql.*;
      import java.util.*;

      public class JDBCTest
      {
              public static void main(String... argv) throws Exception
              {
                      String[] urls = new String[] {"jdbc:derby:sample", "jdbc:sybase:Tds:server:4100/test"};
                      if (argv.length > 0 && argv[0].equals("y")) {
                              loadClass("com.sybase.jdbc4.jdbc.SybDriver");
                              loadClass("org.apache.derby.jdbc.EmbeddedDriver");
                              loadClass("org.apache.derby.jdbc.AutoloadedDriver");
                              loadClass("org.apache.derby.jdbc.AutoloadedDriver40");
                      }
                      for (String url : urls) {
                              System.out.println("Trying to connect to " + url);
                              try { DriverManager.getConnection (url); }catch(SQLException e) { System.out.println(e.getMessage()); }
                      }
              }

              public static void loadClass(String classname) {
                      try { Class.forName(classname); } catch(ClassNotFoundException e) { System.out.println("Class not found: " + classname); }
              }
      }

      ---------- END SOURCE ----------

            lancea Lance Andersen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: