Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to properly close Java DB embedded

918555Feb 19 2012 — edited Feb 20 2012
hi. 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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 19 2012
Added on Feb 19 2012
4 comments
966 views