Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

java - How to shutdown Derby in-memory database Properly

I'm using derby as an embedded database. Furthermore, I'm using it's in-memory database option for my unit tests.

What I can't figure out is how to properly shut down (A quick look at the code) the Derby database. I beleive I have it working for a standard database but I'm getting different exceptions when attempt similar code on a in-memory database.

I'm going to omit details, I'll add them if other feel are needed.

Basically, I'm trying to shut down my database in these two fashions where my in-memory database is consistently called "eh":

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

then:

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

The former results in an exception but not the one expected. The details are:

java.sql.SQLNonTransientConnectionException: Database 'memory:eh' shutdown.

The latter results in

java.sql.SQLException: Database 'eh' not found.

Based on what I've been able to figure out, we want a SQLException but not the one we receive. On the other hand, the SQLNonTransientConnectionException error seems more appropriate but isn't the right type (though it is derived from SQLException) nor does it have the right state code. The state code end up being: 08006.

The example code I have illustrates that a SQLException with a SQL state of "XJ015".

Note: The example I'm referencing is: WwdEmbedded Program (Java Code).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

XJ015 (with SQLCODE 50000) is the expected (successful) SQLSTATE for complete system shutdown. 08006 (with SQLCODE 45000), on the other hand, is the expected SQLSTATE for shutdown of only an individual database.

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

Shuts down the entire system and should result in XJ015.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...