On Thu, 4 Oct 2001, Brett Knights wrote:

> Date: Thu, 4 Oct 2001 09:57:08 -0700
> From: Brett Knights <[EMAIL PROTECTED]>
> Reply-To: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> Subject: RE: Driver fails to load on two webapps
>
> >
> > Might i try moving the jar to WEB-INF\classes instead of WEB-INF\lib ?
>
> Wouldn't work. Jars are only loaded from the lib directory.
>
>
> As you did I ended up with my driver jar file in a common directory
> (lib/common for tc3.3)
> I have a connection pool manager (bitmechanic) and I keep its jar in the
> WEB-INF/lib file for my web apps.
>
> Everything seems to work properly.
>
> It's odd that the everything-in-its-webapp-lib-directory approach doesn't
> work though.
> The DriverManager is supposed to be ClassLoader aware. What happens when you
> call DriverManager.getDriver(url) from a simple servlet in each webapp? What
> about calling DriverManager.registerDriver() in a load-on-startup servlet in
> each webapp?
>

When you call DriverManager.getDriver(), the code (at least in 1.3.1 - I
assume it's the same elsewhere) tries to load the driver class itself from
the classloader of the *caller* of the getDriver() method.  In your
scenario, it would be called by the servlet, and therefore load the driver
from the webapp class loader (if that's where it was).

However, if you're using a connection pool, you have no guarantees that
the pool implementation uses DriverManager.getDriver().  In particular,
the following scenario will fail:

* Connection pool uses Class.forName() to load the driver class
  (i.e. from the class loader that the *pool* is loaded from).

* Connection pool installed in the shared library directory.

* JDBC driver installed in the /WEB-INF/lib directory.

You'd need to investigate the methodology of your connection pool to see
if this is what is happening to you.  However, the general rule of "put
the connection pool and the JDBC driver in the same place" should take
care of nearly every possible class loading difficulty.

> hth
>

Craig McClanahan

Reply via email to