Database not found, and IFEXISTS=true, so we cant auto-create it

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/Barlekar/onlineshoppings" not found, and IFEXISTS=true, so we cant auto-create it [90146-199] 90146/90146 (Help)

org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database "C:/Users/Barlekar/onlineshoppings" not found, and IFEXISTS=true, so we cant auto-create it [90146-199]


If you are dealing with the Spring Boot project, please change the JDBC URL jdbc:h2:~/test to jdbc:h2:mem:testdb in the login page, which is the default URL configured by Spring Boot.


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>

Have you upgraded H2 recently? This could be the cause.

This is related to the following H2 commit:

https://github.com/h2database/h2database/commit/8b53f3999c6c5c3d5ca29020e2657968f4f59ec4

and the change was made because of this exploit:

https://www.exploit-db.com/exploits/45506

This means that the default for H2 is now to not auto-create databases when run in standalone network mode.

If you have read and understood the above, and you still want to allow the database to be auto-created, then just add the -ifNotExists flag to your h2 start command like this:

java -cp h2*.jar org.h2.tools.Server -ifNotExists

Just 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 changed JDBC URL to

jdbc:h2:mem:testdb

and it's work