SpringBoot integrated H2 database cannot make local connection?

recently I tried to use SpringBoot + JPA + H2 database. In application.properties, I configured the database connection

spring.datasource.url=jdbc:h2:tcp://localhost/D:/H2DataBase/DB/test;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE

but after starting the program, the console output is connected to memory mode, and the output is as follows:

Starting embedded database: url="jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false", username="sa"

Why does this happen? is there an error in the database connection to URL? How to solve? Thank you.

Mar.22,2021

because you use tcp mode and add the auto_server=true parameter, springboot automatically starts H2 in mem mode, but this is not a common H2 mode. H2 is an embedded database and usually should use file or mem mode, so the url, of jdbc should be:

spring.datasource.url=jdbc:h2:file:yourdbname

mem mode is recommended by some books or websites, but I think file mode is better, so that the data saved during development and debugging can be retained after restarting the application, and the file mode is stable and there is no problem. Just keep in mind that the production environment should never be used for h _ 2ame. H _ 2 should only be used for development.

Menu