how to properly close Java DB embedded
918555Feb 19 2012 — edited Feb 20 2012hi. I'm seeking confirmation on how to properly close my Derby Java DB. here's a very brief run down of my app
Class.forName(org.apache.derby.jdbc.EmbeddedDriver);
Connection conn = DriverManager.getConnection("jdbc:derby:;databaseName=sample;create=true");
// do some database ops
// now going to close an individual database. not everything.
DriverManager.getConnection("jdbc:derby:;databaseName=sample;shutdown=true;deregister=false");
My app closes the individual database and not a total shutdown. The app will open other databases but only 1 will be open at any point in time. My question is that last line all I need to do for closing?
Do I still need to call conn.close() in between opening other databases? And if I do then do I call it before like this:
conn.commit();
conn.close();
DriverManager.getConnection("jdbc:derby:;databaseName=sample;shutdown=true;deregister=false");
// will open another db later
or after like this
conn.commit();
DriverManager.getConnection("jdbc:derby:;databaseName=sample;shutdown=true;deregister=false");
conn.close();
// will open another db later
Is conn still valid after a call to DriverManager.getConnection(...shutdown...)?
I have read the coding is handled differently depending on whether we do one of the following:
a) DriverManager.getConnection("jdbc:derby:;databaseName=sample;shutdown=true;deregister=false"); // individual db close
b) DriverManager.getConnection("jdbc:derby:;shutdown=true"); // full shut down
When I exit the app do I need to call anything else as far as clean up goes?
I have read the official Derby guide and am still not sure.