[英]How to connect to HSQLDB in-memory in Spring Boot tests to make a query
I have a Spring Boot application with mysql db, but when running tests HSQLDB is used .我有一个 Spring 启动应用程序和 mysql 数据库,但在运行测试时使用 HSQLDB 。 Is it possible to connect to this in-memory database to execute a query?是否可以连接到这个内存数据库来执行查询? What I have to change in tests/application to run it?我必须在测试/应用程序中更改什么才能运行它? I've already tried to run hsql database manager and connect to this database but it seems to be empty but actually it is not empty because in the application I'm debugging the code and read data from this database.我已经尝试运行 hsql 数据库管理器并连接到该数据库,但它似乎是空的,但实际上它不是空的,因为在应用程序中我正在调试代码并从该数据库读取数据。
You have two options.你有两个选择。
One option is to start an HyperSQL (HSQLDB) Server in Spring. This option is discussed here in the answer How to start HSQLDB in server mode from Spring boot application You then start the HyperSQL DatabaseManagerSwing in a separate Java process and connect to the HyperSQL Server with the URL: jdbc:hsqldb:hsql://localhost/testdb
.一种选择是在 Spring 中启动 HyperSQL (HSQLDB) 服务器。此选项在“ 如何从 Spring 启动应用程序在服务器模式下启动 HSQLDB ”的答案中讨论。然后您在单独的 Java 进程中启动 HyperSQL DatabaseManagerSwing 并连接到 HyperSQL 服务器与 URL: jdbc:hsqldb:hsql://localhost/testdb
。
The alternative option is to start the HyperSQL DatabaseManagreSwing in Spring. You can modify the bean template given for the Server and start org.hsqldb.util.DatabaseManagerSwing
instead of the Server.替代选项是在 Spring 中启动 HyperSQL DatabaseManagreSwing。您可以修改为服务器提供的 bean 模板并启动org.hsqldb.util.DatabaseManagerSwing
而不是服务器。 In this case, the DatabaseManager should connect with the URL: jdbc:hsqldb:mem:testdb
.在这种情况下,DatabaseManager 应该连接到 URL: jdbc:hsqldb:mem:testdb
。
Note in both cases, you need to specify the jdbc:hsqldb:mem:testdb
URL as the Spring data source.请注意,在这两种情况下,您都需要将jdbc:hsqldb:mem:testdb
URL 指定为 Spring 数据源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.