Hi Kathey,

Thanks for the code samples. Unfortunately this didn't do the trick. I am still getting the leaked classloader using the shutdown method you sent over. As before, if I comment just the two stmt.execute() lines the classloader unloads properly. It seems like something happens in the driver once the first statement is executed that causes it to hang on to the classloader. 

And to Alan, yes, I am closing the statement. I've also tried explicitly closing the statement and creating a new one for each command. That also fails. 


On Mon, Apr 12, 2010 at 4:20 PM, Kathey Marsden <kmarsdenderby@sbcglobal.net> wrote:
On 4/12/2010 1:29 PM, Jason von Nieda wrote:
Hi all,

 These actions, even after the proper Derby shutdown procedures cause the classloader to not be unloadable. Can someone take a look at the code below and tell me if I am missing something, or is this perhaps a known issue?
The important thing I think is to shutdown using the same class loader in which Derby is booted.   Below are some code snippets to do this.   I recently checked in a change to 10.6 that shows the class loader for boot and shutdown.  I'll be backporting that soon to 10.5.  The problem I have mostly seen with using the wrong class loader to shutdown is that a subsequent boot attempt fails.

If you don't have direct access to the class loader, you can get it from the connection with getClassLoader()



 private static void shutdownWithLoader(ClassLoader loader) throws Exception {
   DataSource ds = newDataSource(loader,"");
   Class[] argType = {String.class};
   String[] args = new String[] {"shutdown"};
   Method sh = ds.getClass().getMethod("setShutdownDatabase", argType);
   sh.invoke(ds, (Object[]) args);

   try {
   }catch (SQLException se ) {
       if (se.getSQLState().equals("XJ015")) {
       System.out.println("Normal Shutdown");
       throw se;


   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, (Object[]) args);
       return ds;