1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
public String framework = "embedded";
public String driver = "org.apache.derby.jdbc.EmbeddedDriver";
public String protocol = "jdbc:derby:";
[...]
conn = DriverManager.getConnection(protocol + path_to_db, props);
[...]
/*
We end the transaction and the connection.
*/
conn.commit();
conn.close();
System.out.println("Committed transaction and 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;
if (framework.equals("embedded")) {
try {
DriverManager.getConnection("jdbc:derby:;shutdown=true");
}
catch (SQLException se) {
gotSQLExc = true;
}
if (!gotSQLExc) {
System.out.println("Database did not shut down normally");
}
else {
System.out.println("Database shut down normally");
} |
Partager