创建共享的HSQLDB数据库 [英] Creating a shared HSQLDB database

查看:112
本文介绍了创建共享的HSQLDB数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

进程中的HSQLDB数据库不会被其他人打开,即使对于基于文件的存储也是如此。

In-process HSQLDB database are not expected to be opened by others, even for file-based storage.

文档暗示这是可能的:服务器模式高级主题,但我还没有找到如何激活此行为的网址。

The documentation hints that this is possible: Server Modes, Advanced Topics, but I've not yet found a URL for how to activate this behaviour.

是否有人这样做,以便他们可以分享如何?

Did anyone do this so they can share how to?

推荐答案

以下适用于我:


  1. 从您的代码启动服务器,该代码显示在HSQLDB源代码中的org.hsqldb.test.TestBase代码中。类似于:

  1. Start a server from your code, which is shown in the org.hsqldb.test.TestBase code in the HSQLDB source code. Something like:

Server server = new Server();
server.setDatabaseName(0, "test");
server.setDatabasePath(0, "file:/path/to/db");
server.start();


  • 在同一个JVM中,打开与同一个数据库中的连接。普通(非服务器)程序,如:

  • In the same JVM, open a Connection to the same database the way you would in a normal (non-Server) program, like:

    conn = DriverManager.getConnection("jdbc:hsqldb:file:/path/to/db");
    


  • 然后使用conn执行你想要的任何SQL 。

    Then use conn to execute whatever SQL you want.

    在我自己的实验中,这似乎有效,它适用于内存和文件数据库。

    In my own experimentation this appears to work, and it works for in-memory and file database.

    当然,其他JVM需要使用TCP连接到服务器。尝试直接在另一个JVM中打开数据库文件将导致关于数据库被锁定的常见错误。

    Other JVMs, of course, will need to connect to the server using TCP. Trying to open the database file directly in another JVM will result in the usual error about the database being locked.

    这篇关于创建共享的HSQLDB数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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