springboot 2.3.0 while connecting to h2 database

39,684

Solution 1

You can fix this by setting the spring.datasource.url property like so:

spring.datasource.url=jdbc:h2:mem:testdb

Prior to Spring Boot 2.3.0-RELEASE this was the default, but I'm not sure where it's set. As of 2.3.0-RELEASE, the schema looks to be a randomly generated GUID.

Solution 2

Step 1. In application.properties:

spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb

Step 2. Start your Spring Boot App and open:

http://localhost:8080/h2-console/

If you still face issue try pasting the URL value which you mentioned in application.properties jdbc:h2:mem:testdb in

JDBC URL of h2-console 

Then you wont face below mentioned issue Database h2 not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149 (Help)

Solution 3

Actually, your h2 databse is looking for a file called test.mv.db. But that file was not present in your user directory. So, that it just slapping you and asking you to pre-create it in that path.

Note: That is the root file where our H2 DB store all our information.

  1. Add below line in your application.properties file
    spring.datasource.url = jdbc:h2:mem:testdb

  2. Go to your user directory, in my case, it is (C:\Users\subra)

  3. Create a new file called test.mv.db and saved it under all file option like below.

    Save Format

  4. Now restart your app.

  5. Done

Reference Screenshot:

My Problem:

My Problem


The Result

The Result

Solution 4

You are not able to connect to database because you are using old JDBC URL. Every time you start a spring project, JDBC URL changes as well.

Solution: Copy the JDBC URL from console every time you want to connect to a database.

see screenshot

Solution 5

Another reason for the error could be a the missing JDBC dependency:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>

I got the exact same error and this was the issue in my case.

Share:
39,684
Admin
Author by

Admin

Updated on December 20, 2021

Comments

  • Admin
    Admin over 2 years

    In Springboot 2.3.0.RELEASE I am getting the the following error while connecting to h2 database in the console

    Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149