1

I cannot login to my H2 Database event though i see the message that the database is available.

DEBUG [main] [Log Context: ]  org.springframework.jdbc.datasource.DriverManagerDataSource:134 Loaded JDBC driver: org.h2.Driver
DEBUG [main] [Log Context: ]  org.springframework.jdbc.datasource.DriverManagerDataSource:144 Creating new JDBC DriverManager Connection to [jdbc:h2:mem:testdb]
INFO  [main] [Log Context: ]  o.s.boot.autoconfigure.h2.H2ConsoleAutoConfiguration:68 H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:testdb'

My application.properties file looks like this:

spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=

and the database not found error messsage looks like this:

enter image description here

I am using h2database version 2.1.214 and spring boot version 2.5.9

CoderCal
  • 149
  • 1
  • 1
  • 9

1 Answers1

1

at first try to add next properties to the Data Base URL:

DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE

Example:

spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
Jackkobec
  • 5,889
  • 34
  • 34
  • Wow! Looks like that worked. could you explain why? – CoderCal Aug 07 '22 at 20:59
  • I'd had the same problem. This properties control the DB lifecycle. DB_CLOSE_ON_EXIT mean Don't close the database when the VM exits. More details: https://www.h2database.com/html/features.html – Jackkobec Aug 07 '22 at 22:35