Shutting down the system In an embedded environment, when an application shuts down, it should first shut down . Shutting down the system

If the application that started the embedded quits but leaves the Java Virtual Machine (JVM) running, continues to run and is available for database connections.

In an embedded system, the application shuts down the system by issuing the following JDBC call:

DriverManager.getConnection("jdbc:derby:;shutdown=true");

Shutdown commands always raise SQLExceptions.

When a system shuts down, a message goes to the log file:

---------------------------------------------------------------- Thu Sep 13 09:53:21 EDT 2012: Shutting down Derby engine ---------------------------------------------------------------- Thu Sep 13 09:53:21 EDT 2012: Shutting down instance a816c00e-0139-bfe6-bff8-000000a155b8 on database directory C:\sampledb with class loader sun.misc.Launcher$AppClassLoader@9931f5 ----------------------------------------------------------------

If you are running with a security manager on JDK 8 or higher, you must grant permission to deregister the embedded driver in order to fully shut down the system. See "Configuring Java security" in the for details.

Typically, an application using an embedded engine shuts down just before shutting itself down. However, an application can shut down and later restart it in the same JVM session. To restart successfully, the application needs to reload org.apache.derby.jdbc.EmbeddedDriver explicitly, as follows:

Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();

This is an exception to the rule that you do not need to load the driver explicitly when starting .

The JDBC specification does not recommend calling newInstance(), but adding a newInstance() call guarantees that will be booted on any JVM.

If your application will need to restart , you can add the attribute deregister=false to the connection URL to avoid having to reload the embedded driver: DriverManager.getConnection("jdbc:derby:;shutdown=true;deregister=false");

It is also possible to shut down a single database instead of the entire system. See . You can reboot a database in the same session after shutting it down.