与 Derby 有其他连接(只读)

发布于 2024-09-18 19:56:50 字数 191 浏览 4 评论 0原文

我想要做什么:我的应用程序与 Derby DB 具有完整连接,并且我想并行地浏览数据库(只读)(使用不同的工具)。

我不确定 Derby 在内部实际上是如何工作的,但我知道我只能有 1 个到 Derby DB 的活动连接。 但是,由于数据库仅由硬盘上的文件组成,我是否应该能够以只读模式打开与它的其他连接?

有什么工具可以做到这一点吗?

What I want to do: My application has a full connection to a Derby DB, and I want to poke around in the DB (read-only) in parallel (using a different tool).

I'm not sure how Derby actually works internally, but I understand that I can have only 1 active connection to a Derby DB.
However, since the DB is only consisting of files on my HDD, shouldn't I be able to open additional connections to it, in read-only mode?

Are there any tools to do just that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寄人书 2024-09-25 19:56:50

如何运行 Apache Derby DB 有两种可能性。

  1. 嵌入式:您在应用程序中运行数据库 → 只能有一个连接
  2. 客户端:您在单独的进程中将数据库作为服务器启动→具有许多连接的经典数据库

您可以根据驱动器尺寸识别类型。如果驱动程序有超过 2MB,则您使用嵌入式版本。

更新

当您启动 derby 引擎(服务器或嵌入式)时,它会获得对数据库文件的独占访问权限。

如果您需要从多个 Java 虚拟机 (JVM) 访问单个数据库,则需要部署一个服务器解决方案。您可以允许来自多个 JVM 的需要访问该数据库的应用程序连接到服务器。

有关详细信息,请参阅双引导系统行为

There are two possibilities how to run Apache Derby DB.

  1. Embedded: You run DB within your application → only one connection possible
  2. Client: You start DB as server in separate process → classic DB with many connections

You can recognize the type upon driver size. If the driver has more then 2MB that you use embedded version.

Update

When you startup the derby engine (server or embedded) it gets exclusive access to database files.

If you need to access a single database from more than one Java Virtual Machine (JVM), you will need to put a server solution in place. You can allow applications from multiple JVMs that need to access that database to connect to the server.

For details see Double-booting system behavior.

送君千里 2024-09-25 19:56:50

我意识到这是一个老问题,但我想我可能会在解决方案上添加更多细节,因为当前接受的答案中的链接已损坏。

可以在已使用嵌入式数据库的 JVM 中运行 Derby Network Server。使用嵌入式 Derby 数据库的代码不需要更改任何内容,并且可以继续按原样使用数据库,但随着 Derby Network Server 启动,其他程序可以连接到 derby 并访问数据库。

您需要做的就是确保 derbynet.jar 位于类路径上

然后您可以执行以下操作之一

  • 在 derby.properties 文件中包含以下行: derby.drda.startNetworkServer=true

  • 在 java 启动时将该属性指定为系统属性
    java -Dderby.drda.startNetworkServer=true

  • 您可以使用 NetworkServerControl API 从 Java 应用程序中的单独线程启动网络服务器:
    NetworkServerControl 服务器 = new NetworkServerControl();
    server.start (new PrintWriter(System.out));

更多详细信息:http://db.apache.org/derby/docs/10.9/adminguide/tadminconfig814963.html

请记住,这样做不会启用此连接上的任何安全性,因此这不是一个好的选择想法在生产系统上执行此操作。不过,可以添加安全性,记录如下: http:// db.apache.org/derby/docs/10.9/adminguide/cadminnetservsecurity.html

I realize this is an old question, but I thought I might add a little more detail on a solution since links in the currently accepted answer are broken.

It is possible to run the Derby Network Server within a JVM that is using the embedded database already. The code that is using the embedded Derby database doesn't need to change anything and can keep using the DB as is, but with the Derby Network Server started, other programs can connect to derby and access the database.

All you need to do is ensure that derbynet.jar is on the classpath

And then you can do one of the following

  • Include the following line in the derby.properties file: derby.drda.startNetworkServer=true

  • Specify the property as a system property at java start
    java -Dderby.drda.startNetworkServer=true

  • You can use the NetworkServerControl API to start the Network Server from a separate thread within a Java application:
    NetworkServerControl server = new NetworkServerControl();
    server.start (new PrintWriter(System.out));

More details here: http://db.apache.org/derby/docs/10.9/adminguide/tadminconfig814963.html

Keep in mind that doing this does not enable any security on this connection, so it is not a good idea to do this on a production system. It is possible to add security though and that is documented here: http://db.apache.org/derby/docs/10.9/adminguide/cadminnetservsecurity.html

因为看清所以看轻 2024-09-25 19:56:50

另外两个想法:

  1. 在您的应用程序中,当数据库未主动使用时关闭数据库并关闭连接。这样您的应用程序就不会干扰尝试打开数据库的另一个工具。
  2. 通过备份来制作数据库的副本(您可以在应用程序打开数据库时执行此操作),然后将该备份恢复到磁盘上的单独位置。然后您可以使用其他工具轻松访问复制的数据库。

Two other ideas:

  1. In your application, shut down the database and close the connection when the database is not actively in use. Then your application won't interfere with another tool which is trying to open the database.
  2. Make a copy of your database, by taking a backup (you can do this while the database is open by your application), then restore that backup to a separate place on your disk. Then you can use another tool to access the copied database at your ease.
魂牵梦绕锁你心扉 2024-09-25 19:56:50

如果您有足够的内存并且不需要最新数据,那么您可以通过创建内存副本来从多个 JVM 访问只读数据库:

ij> connect 'jdbc:derby:memory:memdb;restoreFrom=mydb';

If you can afford the memory and do not need up-to-date data, then you can access read-only databases from multiple JVMs by creating in-memory copies:

ij> connect 'jdbc:derby:memory:memdb;restoreFrom=mydb';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文