与 Derby 有其他连接(只读)
我想要做什么:我的应用程序与 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如何运行 Apache Derby DB 有两种可能性。
您可以根据驱动器尺寸识别类型。如果驱动程序有超过 2MB,则您使用嵌入式版本。
更新
当您启动 derby 引擎(服务器或嵌入式)时,它会获得对数据库文件的独占访问权限。
有关详细信息,请参阅双引导系统行为。
There are two possibilities how to run Apache Derby DB.
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.
For details see Double-booting system behavior.
我意识到这是一个老问题,但我想我可能会在解决方案上添加更多细节,因为当前接受的答案中的链接已损坏。
可以在已使用嵌入式数据库的 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
另外两个想法:
Two other ideas:
如果您有足够的内存并且不需要最新数据,那么您可以通过创建内存副本来从多个 JVM 访问只读数据库:
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: