"Aljosa Mohorovic" <aljosa.mohorovic@gmail.com> said:
>i'm getting "Cannot load JDBC driver class 'com.ibm.db2.jcc.DB2Driver'"
>error but this code works:
[quoted text clipped - 6 lines]
>Connection conn = DriverManager.getConnection(url, user, password);
><<<
... and you have the IBM JDBC driver library in WEB-INF/lib, I suppose?
If so, this all makes sense.
The code above, when being part of the web-application, will have the
jar files in WEB-INF/lib as part of its classpath.
>context.xml:
>>>>
[quoted text clipped - 10 lines]
></Context>
><<<
However, when you specify the DB connection in context.xml (or server.xml),
the classpath used to look for the JDBC library is a combination of
server classpath and common classpath. Application-specific classes
(those within WEB-INF/lib and WEB-INF/classes) are not seen by this
classloader.
>code not working:
>>>>
[quoted text clipped - 8 lines]
>}
><<<
The code as such seems correct.
Relocate (really _relocate_; don't leave a copy within WEB-INF/lib) the
JDBC driver to somewhere where the common classloader will pick it up.
That way it'll be visible to both the server and the application
(should the application need some IBM-specific interfaces of the
library).

Signature
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)