My goal is:
I want to use a specific version of Derby which I ship with my app and I
don't want to interfere with any other derby versions loaded in the
same JVM or have them interfere with me. I am creating a new
datasource in a separate URLClassLoader and using that for creating all
my connections. Are there other things I need to do to meet my goal?
I have a feeling it all must be more complex than it looks to me right now.
Thanks
Kathey
Below is some code showing what I have done in playing with this so far.
Method to load derby in separate loader and create datasource:
private static DataSource newDataSource(ClassLoader loader, String
databaseName) throws Exception
{
DataSource ds = (DataSource)
loader.loadClass("org.apache.derby.jdbc.EmbeddedDataSource").newInstance();
// setDatabaseName with reflection
Class[] argType = {String.class};
String[] args = new String[] {databaseName};
Method sh = ds.getClass().getMethod("setDatabaseName", argType);
sh.invoke(ds, args);
return ds;
}
// Calling program ....
.....
URL[] urls =
new URL[]{new URL(derbyJarURLString)};
System.out.println(urls[0].getFile());
ClassLoader loader1 =new URLClassLoader(urls);
DataSource ds = newDataSource(loader1,"mydb;create=true");
ds.getConnection();
...