You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Krasimir Nedkov (JIRA)" <ji...@apache.org> on 2010/05/04 14:08:56 UTC

[jira] Created: (DBCP-333) Unable to create a JDBC driver using custom class loader

Unable to create a JDBC driver using custom class loader
--------------------------------------------------------

                 Key: DBCP-333
                 URL: https://issues.apache.org/jira/browse/DBCP-333
             Project: Commons Dbcp
          Issue Type: Bug
    Affects Versions: 1.3
            Reporter: Krasimir Nedkov


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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DBCP-333) Unable to create a JDBC driver using custom class loader

Posted by "Krasimir Nedkov (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DBCP-333?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Krasimir Nedkov updated DBCP-333:
---------------------------------

    Affects Version/s: 1.4

> Unable to create a JDBC driver using custom class loader
> --------------------------------------------------------
>
>                 Key: DBCP-333
>                 URL: https://issues.apache.org/jira/browse/DBCP-333
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4
>            Reporter: Krasimir Nedkov
>
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DBCP-333) Unable to create a JDBC driver using custom class loader

Posted by "Phil Steitz (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DBCP-333?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Phil Steitz updated DBCP-333:
-----------------------------

    Fix Version/s: 1.3.1
                   1.4.1

> Unable to create a JDBC driver using custom class loader
> --------------------------------------------------------
>
>                 Key: DBCP-333
>                 URL: https://issues.apache.org/jira/browse/DBCP-333
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.3, 1.4
>            Reporter: Krasimir Nedkov
>             Fix For: 1.3.1, 1.4.1
>
>
> 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

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.