简体   繁体   English

如何在 Spring 引导测试中连接到内存中的 HSQLDB 以进行查询

[英]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.

相关问题 内存数据库配置(HSQLDB),用于Spring启动应用程序中的集成测试 - In-memory database configuration (HSQLDB) for integration testing in spring boot app 如何在集成测试中设置保存点(hsqldb在内存中)? - How can to set savepoint in integration tests (with hsqldb in-memory)? 如何使用Spring通过脚本初始化内存中的HSQLDB - How to initialize in-memory HSQLDB using script via Spring 用于功能测试的Spring Boot内存DynamoDB / DAX解决方案? - Spring boot in-memory DynamoDB/DAX solution for functional tests? HSQLDB内存设置的HSQLDB约束违规和SQL查询日志 - HSQLDB Constraint Violation & SQL Query Log for an HSQLDB in-memory setup 与内存中的hsqldb对称 - symmetricds with in-memory hsqldb HSQLDB内存数据库JDBC模板查询失败 - HSQLDB In-memory database JDBC Template Query failing 如何正确集成 HSQLDB 与 Spring 引导? - How to correctly integrate HSQLDB with Spring Boot? 如何连接到通过Spring实例化的hsqldb - how to connect to hsqldb which is instantiated through spring 如何使用 Spring Boot 针对真实数据库而不是在内存中一次性运行 @DataJpaTest - How to one-off run @DataJpaTest against real database instead of in-memory with Spring Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM