How to shutdown Derby in-memory database Properly

纵然是瞬间 提交于 2019-11-30 03:35:24

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.

The URL "jdbc:derby:memory:eh;shutdown=true" results in the expected 08006 error code, but doesn't actually remove the DB from memory. If later on, you try to create a new database with "jdbc:derby:memory:eh;create=true", you'll get an error saying that the database already exists.

Fortunately, as of Derby 10.6.1.0 (released on May 17, 2010), it is possible to actually drop an in-memory database using a URL of the form "jdbc:derby:memory:eh;drop=true". See the release notes and the page Using in-memory databases.

I believe that your first code example is fine. The SQL State difference that you are seeing, I believe, is because you are running Derby embedded, but the example code that you saw (with SQL state XJ015) was running in a client-server configuration.

As you noted, the SQLNonTransientConnectionException is a subclass of SQLException, so I am confused as to why you think you are not getting the right type of exception.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!