You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Bernd Ruehlicke <BR...@lgc.com> on 2005/02/25 22:04:14 UTC

Shutdown and reconnection results in "No suitable Driver"

Here a strange situation. I have a main JVM which has a Derby Embedded
connection. It spinns off to call a script which again will make a Derby
Connection. To allow this Embedded I have to disconnect from Derby in
the first JVM. It turned out I had to use Shutdown in th efirsyt to let
the second jvm allow to connect
 
// shutting down a database from your application
DriverManager.getConnection(
    "jdbc:derby:;shutdown=true");
 
So far so good. Now when JVM number one want to reestablish it's
connection via the usual Class.forName(...) ...
DriverGetConnection(url,user,passw) 
 
I get
 
a java.sql.SQLException: No suitable Driver 
 
 
I have created a JUnit test which simply just Loops over a connection ,
a shutdown and a new connection - it fails with the 2. connection. see
code snipled below. Trust me that the url is correct and that the first
time it goes via the loop it connect correctly.
 
 
Any thoughts ?!!
 
B-)
 
   .....
         for(int tal=0;tal<10;tal=tal+1)
         {
             Class.forName(driver);
             System.out.println("Running for number : "+tal);
             System.out.println("Loaded the appropriate driver.");
                  
             _connection = DriverManager.getConnection(url +
";create=true", user, pass);
             
             if(tal<9)this.tearDown();
         }

......
 
 
where tearDown() is
     protected void tearDown()
     {
         try
         {
             // Now try to disconnect
             _connection.close();
             _connection = null;
             System.out.println("Closed connection");
 
             /*
                In embedded mode, an application should shut down Derby.
                If the application fails to shut down Derby explicitly,
                the Derby does not perform a checkpoint when the JVM
shuts down, which means
                that the next connection will be slower.
                Explicitly shutting down Derby with the URL is
preferred.
                This style of shutdown will always throw an "exception".
              */
             boolean gotSQLExc = false;
 
             try
             {
 
DriverManager.getConnection("jdbc:derby:;shutdown=true");
             }
             catch(SQLException se)
             {
                 gotSQLExc = true;
             }
 
             if(!gotSQLExc)
             {
                 _logger.fine("Database did not shut down normally");
             }
             else
             {
                 _logger.fine("Database shut down normally");
             }
         }
         catch (Throwable e)
         {
             _logger.fine("exception thrown:"+e.getMessage());
                 e.printStackTrace();
         }
 
         System.out.println("TestDerby finished");
 
     }