如何正确关闭Derby内存数据库 [英] How to shutdown Derby in-memory database Properly

查看:200
本文介绍了如何正确关闭Derby内存数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用derby作为嵌入式数据库。此外,我正在使用它的内存数据库选项进行单元测试。

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

我无法弄清楚如何正确关闭(快速查看代码) Derby数据库。我相信我让它适用于标准数据库但我在内存数据库中尝试类似代码时会遇到不同的异常。

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.

基本上,我正试图以这两种方式关闭我的数据库,我的内存数据库一直被称为eh:

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");

然后:

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

前者导致一个例外但不是预期的那个。细节是:


java.sql.SQLNonTransientConnectionException:数据库'内存:eh'关闭。

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

后者导致


java.sql.SQLException:数据库'呃'不是发现。

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

根据我能够弄清楚的,我们想要一个 SQLException 但不是我们收到的那个。另一方面, SQLNonTransientConnectionException 错误似乎更合适但不是正确的类型(尽管它来自 SQLException )也没有正确的州代码。状态代码最终为: 08006

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.

我的示例代码说明了 SQLException ,SQL状态为XJ015。

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

注意:我引用的示例是: WwdEmbedded Program Java Code

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

推荐答案

XJ015(带 SQLCODE 50000)是预期的(成功) SQLSTATE 完成系统关机。另一方面,08006( SQLCODE 45000)是仅关闭单个数据库的预期 SQLSTATE

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");

关闭整个系统并导致 XJ015

这篇关于如何正确关闭Derby内存数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆