1

This is my first spring boot application. I am trying to connect the database using h2-console. But when I trying to do it I am getting an error. The error is,

Database "/Users/MyName/test" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149 (Help)

enter image description here

I have shown h2-conosle image above. I did not use any code in application.property file. As well as I have used below mentioned dependency also.

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
</dependency>

First My port was 8080 Then also this not worked. After that, the port has been changed to 8082. even it not working.

user_v12
  • 529
  • 4
  • 13
  • This may help [Database does not exist](https://stackoverflow.com/questions/58298381/database-c-data-sample-not-found-and-ifexists-true-so-we-cant-auto-create-i) – Asmat K May 10 '20 at 20:45

3 Answers3

0

The easy way to fix the problem may be to change the JDBC URL to jdbc:h2:mem:testdb

Another way to fix the issue is to add a version number with the maven dependency (from https://mvnrepository.com/artifact/com.h2database/h2). If you could add the dependency like below and rerun the application, the URL will be corrected.

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version>1.4.200</version>
    <scope>test</scope>
 </dependency>


    
sasikumar
  • 1
  • 2
0

One more easy way to create the database in Windows is when you run the C:\Program Files (x86)\H2\bin h2w.bat, you get a option as shown in the screen shots. You can create the database using the option Create a new database. And then use the same connection details to connect to the newly created h2 database.

Windows Screenshot

Windows Db Creation Screenshot

0

First approach

  1. Search for h2 in spring boot logs, there will be log like H2 console available at '/console'. Database available at 'jdbc :h2:mem:5bcffde7-27bd-4d59-9ad1-3bc12635f0bf'. Note: /console is the path, i chosen for h2-console in application.properties, this will vary according to the path you have chosen.
  2. Copy the url without single quotes and no spaces between them i.e jdbc:h2:mem:5bcffde7-27bd-4d59-9ad1-3bc12635f0bf.
  3. Enter this in the JDBC Url in h2-console.
  4. Then you should be able to connect to it.

The second and simpler approach

Configuring the h2 database url in application.properties without the need of spring randomly generating it.

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