db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David W. Van Couvering" <David.Vancouver...@Sun.COM>
Subject Re: Question about using URLClassLoader and Derby
Date Wed, 09 Nov 2005 17:14:30 GMT
Hi, Kathey.  At first glance it looks good to me.  I'm assuming *all* 
classes your app needs are available to the from the URL you specify, 
because you are not specifying a parent classloader when you create it. 
  Also, you'll need to make sure you give the class that runs this code 
the permission to load classes (I'm not sure exactly how this is done, I 
just know it's an issue).

But I am no classloader guru.  I am forwarding this to folks I know 
within Sun who have done a *lot* of work within classloaders as part of 
the app server effort.  I'll get back to you with any information I get.


Kathey Marsden wrote:
> 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();
>    ...

View raw message