Bug 48773 - DataSourceWrapper and DriverManager problems
Summary: DataSourceWrapper and DriverManager problems
Alias: None
Product: Taglibs
Classification: Unclassified
Component: Standard Taglib (show other bugs)
Version: nightly
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2010-02-19 04:58 UTC by Jarek Gawor
Modified: 2010-10-09 18:28 UTC (History)
0 users

Patch for this issue. (2.58 KB, patch)
2010-02-19 04:58 UTC, Jarek Gawor
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jarek Gawor 2010-02-19 04:58:17 UTC
Created attachment 25022 [details]
Patch for this issue.

In certain situations the DataSourceWrapper is not able to connect to the database even if a driver class name was explicitly set. The core of the problem is that the DriverManager uses the caller's classloader (in this case the classloader of DataSourceWrapper) to find a driver for the given url. In some cases the classloader of DataSourceWrapper might be totally different and separate from the context classloader that registered the driver with DriverManager. In these cases the DriverManager will not "see" the driver registered earlier because of the different classloaders and the DataSourceWrapper.getConnection() will fail with "unable to find suitable driver" type of error message.

One easy work solution for this problem is to actually use the driver object that was registered in setDriverClassName() to connect to the database. And if the connection fails then fallback to using the DriverManager API.
Comment 1 Jeremy Boynes 2010-10-09 18:28:25 UTC
Patch applied as r1006229.