简体   繁体   中英

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 . 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.

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 .

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. In this case, the DatabaseManager should connect with the URL: jdbc:hsqldb:mem:testdb .

Note in both cases, you need to specify the jdbc:hsqldb:mem:testdb URL as the Spring data source.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM