java 如何在仅内存模式下运行 HSQLDB 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1497855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 16:46:27  来源:igfitidea点击:

How to run a HSQLDB server in memory-only mode

javahsqldb

提问by Juri Glass

In the documentation of the HSQLDB is a command line statement to start a HSQLDB server (HSQLDB Doc). But there is this "file:mydb" property, so I assume its not in memory-only mode.

在 HSQLDB 的文档中有一个命令行语句来启动一个 HSQLDB 服务器(HSQLDB Doc)。但是有这个“file:mydb”属性,所以我假设它不是仅内存模式。

How do I run a memory-only HSQLDB server?

如何运行仅内存的 HSQLDB 服务器?

I ran the following but get no clue.

我运行了以下但没有任何线索。

java -cp ../lib/hsqldb.jar org.hsqldb.Server -?

采纳答案by Chii

use java -cp .\hsqldb-1.8.0.10.jar org.hsqldb.Server -database.0 mem:aname

利用 java -cp .\hsqldb-1.8.0.10.jar org.hsqldb.Server -database.0 mem:aname

In memory mode is specified by the connection url - so if you want, you can just have a server.properties file in the same directory, and set the connection url to use the memprotocol - or if you are using hsqldb in another application that allows you to specify the connection url such as jdbc, specify jdbc:hsqldb:mem:aname.

在内存模式下由连接 url 指定 - 所以如果你愿意,你可以在同一目录中有一个 server.properties 文件,并设置连接 url 以使用mem协议 - 或者如果你在另一个允许的应用程序中使用 hsqldb你要指定jdbc等连接url,指定jdbc:hsqldb:mem:aname.

回答by Shajee Lawrence

It took around 2 days for me to figure out on how to start a server in-memory and then access from outside. Hope this will save someone's time.

我花了大约 2 天的时间才弄清楚如何在内存中启动服务器,然后从外部访问。希望这会节省某人的时间。

Server server = new Server();
server.setDatabaseName(0, "mainDb");
server.setDatabasePath(0, "mem:mainDb");
server.setDatabaseName(1, "standbyDb");
server.setDatabasePath(1, "mem:standbyDb");
server.setPort(9001); // this is the default port
server.start();

When you have to access the in-memory database for any CRUD, here is what you need to do :-

当您必须访问任何 CRUD 的内存数据库时,您需要执行以下操作:-

String url="jdbc:hsqldb:hsql://192.168.5.1:9001/mainDb";
Class.forName("org.hsqldb.jdbc.JDBCDriver");
Connection conn = DriverManager.getConnection(url, "SA", "");

where 192.168.5.1 is the server ip where HSQL is running. To connect to the standbyDb, replace mainDb with standbyDb in the first line. Once you get the connection, you can perform all database related operations.

其中 192.168.5.1 是运行 HSQL 的服务器 IP。要连接到standbyDb,请将第一行中的mainDb 替换为standbyDb。一旦获得连接,就可以执行所有与数据库相关的操作。

To connect to the server from remote using DatabaseManagerSwing, here is what you need to do.

要使用 DatabaseManagerSwing 从远程连接到服务器,您需要执行以下操作。

Download hsqldb-x.x.x jar and copy it to a folder (x.x.x is the version) open a terminal or command prompt and cd to the folder and run

下载 hsqldb-xxx jar 并将其复制到一个文件夹(xxx 是版本)打开终端或命令提示符并 cd 到该文件夹​​并运行

java -cp hsqldb-x.x.x.jar org.hsqldb.util.DatabaseManagerSwing

Select "HSQL Database Engine Server" from the Type drop down and give "jdbc:hsqldb:hsql://192.168.5.1:9001/mainDb" as the URL. This will connect you to the remote HSQL in-memory Server instance.

从类型下拉列表中选择“HSQL 数据库引擎服务器”并提供“jdbc:hsqldb:hsql://192.168.5.1:9001/mainDb”作为 URL。这会将您连接到远程 HSQL 内存中服务器实例。

Happy Coding !!
DbManagerSwing UI

快乐编码!!
数据库管理器Swing UI

回答by Todd R

I believe the file is used to load up the db into memory, and then persist when Server stops. I don't think the file is accessed while you're running.

我相信该文件用于将数据库加载到内存中,然后在服务器停止时保留。我认为在您运行时不会访问该文件。

It's been awhile since I've used HSQLDB (or H2), but I'm pretty sure that's how it works.

我已经有一段时间没有使用 HSQLDB(或 H2)了,但我很确定它是这样工作的。