commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GMail - Ugo Gagliardelli <ugo.gagliarde...@gmail.com>
Subject [dbcp] BasicDataSource.createConnectionFactory() fails
Date Tue, 10 Jan 2012 12:23:11 GMT
I'm trying to use BasicDataSource 1.3 (latest release downloaded just 
now) using a custom classloader. In other words I set a ClassLoader with 
setDriverClassLoader method.
When I try to create a connection, I get an SQL Exception from 
createConnectionFactory(). Looking at source code, I see that 
createConnectionFactory method, still use:
  driver = DriverManager.getDriver(url);
that will not use the correct classloader, infact it uses what returned 
by getCallerClassLoader(), that's a classloader not able to resolve the 
driver class.

How can I have this figure work?

This is my code (Spring based):

<bean id="propertyConfigurer"
         
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>file:///${user.dir}/config.properties</value>
</property>
</bean>

<bean id="jarClassloarder" class="java.net.URLClassLoader">
<constructor-arg>
<list>
<bean id="jarURL" class="java.net.URL">
<constructor-arg value="file://${db.driver.jar}"/>
</bean>
</list>
</constructor-arg>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassLoader" ref="jarClassloarder" />
<property name="driverClassName">
<value>${db.driver.class}</value>
</property>
<property name="url">
<value>${db.driver.url}</value>
</property>
<property name="username">
<value>${db.driver.username}</value>
</property>
<property name="password">
<value>${db.driver.password}</value>
</property>
</bean>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message