0

I'm learning Spring boot and I'm trying to create a very simple RESTful API that access an in-memory database and perform CRUD actions.

However, everytime I try to Connect or Test Connection on http://localhost:8080/h2-console, I get this error:

"Database "C:/Users/XXX/test" not found, and IFEXISTS=true, so we cant auto-create it [90146-199] 90146/90146"

https://i.stack.imgur.com/zOrp1.jpg

I followed EXACTLY the instructions from http://www.springboottutorial.com/spring-boot-crud-rest-service-with-jpa-hibernate. I have tried everything I could find online: using jdbc:h2:mem:test as JDBC URL etc, but none of them worked for me and I'm not sure what am I doing wrong. I didn't install h2 database from the official website as I read it is not necessary to use the in-memory module (and I still don't know if I should've installed it or not, as there is not a single mention of it online, as far as I checked).

Any thoughts? I'm a beginner when it comes to Spring Boot and I'm really lost. I just want to test CRUD actions and I don't care about the persistence of the DB.

I have provided my application.properties below.

Thank you! :)

# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2

# Datasource
spring.datasource.url=jdbc:h2:mem:test
spring.datasource.username=user
spring.datasource.password=user
spring.datasource.driver-class-name=org.h2.Driver
XD129
  • 1
  • 1
  • 2
  • Check if the application is actually up and running. Read the logs. If you can't get anything else to work, follow one of the spring.io guides (they may be more up to date than the springboottutorial site, and also have the advantage of taking only a few minutes to get up and running), and see if you can reproduce the problem there or not. – Nathan Hughes Apr 16 '19 at 19:16
  • Yes, it is. It works totally fine. There is no error showing on the console at all, that's why I'm confused. I also could not use H2 database with Play Framework, as I got some errors too (TABLE DOES NOT EXIST). Just to test, I've just downloaded H2, created a database and it worked, lol. Not sure what's happening here, but I really would like to use the in-memory module as I'm planning on post it on github to help other people who are also learning Spring Boot (so they don't need to download H2 and do what I've just done). – XD129 Apr 16 '19 at 19:20
  • Done. Well, I'm still having this strange error. Can anybody please help me out? Thanks! – XD129 Apr 16 '19 at 20:21
  • unfortunately for the time being (Aug '19) the only thing that worked for me was to downgrade h2 version as in this related post: https://stackoverflow.com/questions/55349373/database-not-found-and-ifexists-true-so-we-cant-auto-create-it – hello_earth Aug 16 '19 at 10:04

2 Answers2

7

Make sure your url in h2-console(refer screenshot below) is same as your 'spring.datasource.url=jdbc:h2:mem:test'.

It worked for me.

enter image description here

UPDATE: Other alternative solution is, you can avoid setting spring.datasource.url property. Spring will automatically set this default JDBC url for you.

happy learning.. Upvote, if it is sovled your issue.

Bandham Manikanta
  • 1,858
  • 21
  • 21
3

In your spring application.properties file, set the property spring.datasource.url=jdbc:h2:~/test

Then restart the application and open http://localhost:8080/h2-console/ Click on Test Connection button, you should see "Test successful".

DanielM
  • 3,598
  • 5
  • 37
  • 53
Venkat T
  • 31
  • 4