I am getting error after opening the h2 database console. I enter database name but it is showing database not found error:
Database \"C:/Users/Barlek
I have faced this issue and resolved in the following way
To use H2 Database - Your application should be running in JDK Environment, not JRE Environment , to change please use below steps :
jdbc:h2:~/test
, it should actually match with the spring boot application properties
spring.datasource.url=jdbc:h2:mem:testdb
so replace the url in the login console and click on connect I have used [Ivan Xue][2] provided steps here -> https://stackoverflow.com/a/56539107Just append this to the application.properties file:
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
I found that you can add a parameter to the "-ifNotExists" start options when booting up h2 db. Programmatically, you can do it this way:
Server.createTcpServer("-tcpPort", "[PORT]", "-tcpAllowOthers", "-ifNotExists").start();
If you are using the command prompt, the same applies
Use a pre-2019 version of the H2
database dependency that auto-creates the database every time you run your standalone application. For example version 1.4.193
. Your pom.xml
should include this dependency:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.193</version>
</dependency>
Check The jdbc Url used in h2 console to see if it match what you have specified
Along with h2 dependency in POM :
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
I added jpa, crud repository dependency in POM Like given below and It worked fine for me:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>