Uploaded image for project: 'Commons DBCP'
  1. Commons DBCP
  2. DBCP-333

Unable to create a JDBC driver using custom class loader

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.3, 1.4
    • 1.3.1, 1.4.1
    • None

    Description

      Hello,

      I'm unable to instantiate my JDBC driver using a custom class loader:
      BasicDataSource ds = new BasicDataSource();
      String connectURL = "jdbc:mysql://"config.getHost()"/"+config.getDatabaseName();
      ds.setDriverClassName(MySQLStore.MYSQL_DRIVER);
      ds.setDriverClassLoader(config.getClass().getClassLoader());
      .....

      Having a look at the org.apache.commons.dbcp.BasicDataSource.createConnectionFactory() method implementation, I found that the class loader is actually ignored. In the first part of the method there is an attempt to load the class that seems to pass successfully, but the loaded class is not assigned to the driverFromCCL variable:
      if (driverClassLoader == null)

      { Class.forName(driverClassName); }

      else

      { Class.forName(driverClassName, true, driverClassLoader); }

      Then in the second part of the method driverFromCCL is still null and instead of instantiating the driver directly, DriverManager.getDriver(url) is called, which fails:
      if (driverFromCCL == null)

      { driver = DriverManager.getDriver(url); }

      else {
      // Usage of DriverManager is not possible, as it does not
      // respect the ContextClassLoader
      driver = (Driver) driverFromCCL.newInstance();
      if (!driver.acceptsURL(url))

      { throw new SQLException("No suitable driver", "08001"); }

      }

      Kind regards,
      Krasimir

      Attachments

        Issue Links

          Activity

            People

              markt Mark Thomas
              krasimir_nedkov Krasimir Nedkov
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: