Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 60672 invoked from network); 24 Nov 2010 13:06:07 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 24 Nov 2010 13:06:07 -0000 Received: (qmail 33918 invoked by uid 500); 24 Nov 2010 13:06:39 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 33545 invoked by uid 500); 24 Nov 2010 13:06:36 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 33535 invoked by uid 99); 24 Nov 2010 13:06:35 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Nov 2010 13:06:35 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Nov 2010 13:06:34 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id oAOD6EK6027993 for ; Wed, 24 Nov 2010 13:06:14 GMT Message-ID: <6934608.285471290603974389.JavaMail.jira@thor> Date: Wed, 24 Nov 2010 08:06:14 -0500 (EST) From: "Dennie de Lange (JIRA)" To: issues@commons.apache.org Subject: [jira] Commented: (DBCP-333) Unable to create a JDBC driver using custom class loader MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/DBCP-333?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12935314#action_12935314 ] Dennie de Lange commented on DBCP-333: -------------------------------------- Hello, I have the same problem. Please update BasicDataSource.java. Change line 1417: Class.forName(driverClassName, true, driverClassLoader); To: driverFromCCL = driverClassLoader.loadClass(driverClassName); > 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.