views:

44

answers:

2

I’m trying to use an imbedded Derby database from within a war file deployed on WebSphere for Z/OS. When I use code like the following to create a database I wind up creating a derby version 10.3 database using the derby.jar included with WebSphere server 7.0 instead of the version 10.5 derby.jar I include in my WEB-INF/lib directory.

Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:derby:testDB;create=true");
DatabaseMetaData dbmd = conn.getMetaData();
String productName = dbmd.getDatabaseProductName();
String productVersion = dbmd.getDatabaseProductVersion();

How can I force WebSphere to use the org.apache.derby.jdbc.EmbeddedDriver class included in the derby.jar file I package in my war file?

+1  A: 

I think you'll need to switch the default classloader to look into the web app first. Specify PARENT_LAST as documented here : See "Setting classloaders in a Web module"

But this is a risky option since it can affect all other classes which might be duplicated between app and war.

JoseK
+1  A: 

In a J2EE environment, it's better to let the server manage connections, and it's usually not a good idea to put JDBC providers in your WAR.

New in WAS 7.0 is a feature known as "isolated resource providers" that allows you to configure multiple versions of Derby to run in parallel in the same JVM.

bkail