How to make H2 file-based for Spring Boot

35 views
Skip to first unread message

Mobile Visuals

unread,
May 5, 2020, 7:04:35 AM5/5/20
to H2 Database
I have followed tutorials and checked StackOverflow for solutions to this, but found nothing that works. What should I do to make H2 file-based without getting errors? Here is my property file:

spring.h2.console.enabled=true

spring.jpa.database=h2
spring.datasource.url=jdbc:h2:file:~/test

I then get 

org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Wrong user name or password [28000-199]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:459) ~[h2-1.4.199.jar:1.4.199]

I don't know why I have to add user name and password when this was not required without the file-based URL. I have tried to add the user name and password, but it results in other errors.

Evgenij Ryazanov

unread,
May 5, 2020, 7:12:54 AM5/5/20
to H2 Database
Hello.

It looks like you already have a database with the name test in your home directory and this database has a user with some name and password; you need to specify them.

If you don't know them, you can try to use the recovery tool, but if you don't need data in this database, you can simply delete its file to create a new empty database.

Mobile Visuals

unread,
May 6, 2020, 7:13:58 AM5/6/20
to H2 Database
You were right! I had created several test databases before. To avoid conflict with any of them, I changed the URL to a rare database name:

spring.datasource.url=jdbc:h2:file:~/test2hjhj
Reply all
Reply to author
Forward
0 new messages