[jboss-as7-dev] problem with the classloader, not able to load a JDBC driver

Flemming Harms flemming.harms at gmail.com
Tue Jul 24 08:53:00 EDT 2012


Thanks!

I had to do one more thing to make it work with the module class loader,
since the database driver was loaded in it's own class loader and it was
not known to the current class loader I had to find a way to make it
available

I solve it by wrapping the driver in my own class and register the driver
to the DriverManager

Like this :
 DriverManager.registerDriver(new DatabaseDriverWrapper(driver));
 DriverManager.getConnection(url, user, password);

2012/7/23 Tomaž Cerar <tomaz.cerar at gmail.com>

>
>
> On Mon, Jul 23, 2012 at 5:58 PM, Jason T. Greene <jason.greene at redhat.com>wrote:
>
>> On 7/23/12 10:51 AM, Jesper Pedersen wrote:
>> > On 07/23/2012 11:42 AM, Flemming Harms wrote:
>> >> I found a solution to my problem. Had to update the xsd schema with an
>> >> extra attribute "module" and then user need pack his JDBC driver as
>> module.
>> >>
>> >> I use the code below to load the model and the driver class.
>> >>
>> >> Class<?> driverClass =
>> >>
>> Module.loadClassFromCallerModuleLoader(ModuleIdentifier.fromString(moduleName),
>> >> driver);
>> >> driverClass.newInstance();
>> >>
>> >> <outbound-connections>
>> >>           <database>
>> >>               <connection module="com.h2database.h2"
>> >> driver="org.h2.jdbcx.JdbcDataSource" name="db"
>> >> url="jdbc:h2:/tmp/test;DB_CLOSE_DELAY=-1" username="sa" password=""
>> >> min-pool-size="10" max-pool-size="20" />
>> >>           </database>
>> >> </outbound-connections>
>> >>
>> >> Does it make sense?
>> >
>> > The -ds.xml functionality uses the module through the <driver> tag, so
>> > this would be similar.
>> >
>> > Things to watch out for is of course the password attribute - it should
>> > at least support the vault mechanism I would say.
>>
>> If you make the attribute definition have expressions=true, it will
>> automatically enable vault support.
>>
>> given that you use AD.parseAndSetParameter() when parsing and setting
> field and  AD.resolveModelAttribute() when getting data from model
>
>>  --
>> Jason T. Greene
>> JBoss AS Lead / EAP Platform Architect
>> JBoss, a division of Red Hat
>> _______________________________________________
>> jboss-as7-dev mailing list
>> jboss-as7-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/jboss-as7-dev
>>
>
>
> _______________________________________________
> jboss-as7-dev mailing list
> jboss-as7-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/jboss-as7-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-as7-dev/attachments/20120724/5dbb3dfc/attachment.html 


More information about the jboss-as7-dev mailing list