db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig Russell <Craig.Russ...@Sun.COM>
Subject Re: derby jdbc load driver
Date Wed, 10 Aug 2005 22:37:48 GMT
Hi,

Java has this concept of a shutdown hook that can be registered with  
Runtime.getRuntime().addShutdownHook(Thread hook). The implementation  
class of the hook defines a run() method that would do  
DriverManager.getConnection("jdbc:derby:;shutdown=true") for the  
database that registered the hook.

It might be good to experiment with this (sorry, I can't volunteer)  
and see whether the Derby runtime can be made more robust in the face  
of usage which does not shut down Derby cleanly.

We use this hook concept with JDO's FOStore implementation. When the  
VM is shut down without cleanly closing the FOStore connection, our  
hook writes dirty buffers to disk and terminates.

Craig

On Aug 9, 2005, at 2:51 PM, Bernd Ruehlicke wrote:

> I can confirm this.
>
> In additon shut it down gracefully alla the code below which I  
> found in
> some doc while fighting with the forgotten .newInstance()
>
>
>
>      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("Derby finished");
>
>      }
>
>
> B-)
>
>
>
>
>> -----Original Message-----
>> From: Satheesh Bandaram [mailto:satheesh@Sourcery.Org]
>> Sent: Tuesday, August 09, 2005 4:32 PM
>> To: Derby Discussion
>> Subject: Re: derby jdbc load driver
>>
>> I think Derby recommends using .newInstance() to load JDBC
>> drivers... In fact, it is required if you plan to shutdown
>> and reboot databases on the same thread/VM for Derby. Take a
>> look at the javadoc for EmbeddedDriver.
>>
>> http://db.apache.org/derby/javadoc/engine/org/apache/derby/jdb
>> c/EmbeddedDriver.html
>>
>> Satheesh
>>
>> Oyvind.Bakksjo@Sun.COM wrote:
>>
>>     Bogdan Mihaila wrote:
>>
>>
>>         Hello!
>>
>>         I'm trying to load the embedded derby driver,
>> like this:
>>
>>
>> Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
>>
>>
>>
>>     As Rajesh pointed out, the problem is most likely the
>> CLASSPATH. If you still have problems, please send the
>> complete exception, including stack trace, as this helps to
>> figure out the problem.
>>
>>     By the way, you don't need the '.newInstance()' part -
>> simply loading the driver class will set up the Derby system.
>>
>>
>>
>> ________________________________
>>
>> This e-mail, including any attached files, may contain
>> confidential and privileged information for the sole use of
>> the intended recipient. Any review, use, distribution, or
>> disclosure by others is strictly prohibited. If you are not
>> the intended recipient (or authorized to receive information
>> for the intended recipient), please contact the sender by
>> reply e-mail and delete all copies of this message.
>>
>>
>>
> ----------------------------------------------------------------------
> This e-mail, including any attached files, may contain confidential  
> and privileged information for the sole use of the intended  
> recipient.  Any review, use, distribution, or disclosure by others  
> is strictly prohibited.  If you are not the intended recipient (or  
> authorized to receive information for the intended recipient),  
> please contact the sender by reply e-mail and delete all copies of  
> this message.
>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Mime
View raw message