In my Spring Boot application, I'm trying to configure the path for H2 database folder. I want to place it by the following path:
/home/public/h2
The configuration like:
# Datasource
spring.datasource.url=jdbc:h2:file:/home/public/h2
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
leads to the following error:
Caused by: org.h2.jdbc.JdbcSQLException: A file path that is implicitly relative to the current working directory is not allowed in the database URL "jdbc:h2:file:/home/public/h2". Use an absolute path, ~/name, ./name, or the baseDir setting instead. [90011-197]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:357) ~[h2-1.4.197.jar:1.4.197]
I also tried spring.datasource.url=jdbc:h2:file:~/home/public/h2
but it doesn't work.
What am I doing wrong and how to properly configure the path?
Please try to use jdbc:h2:./name
(explicit relative path), or
set the system property h2.implicitRelativePath
to true (to prevent this check).
For Windows, an absolute path also needs to include the drive ("C:/...")
.
h2.implicitRelativePath=true
spring.datasource.url=jdbc:h2:~/home/public/h2
or
h2.implicitRelativePath=true
spring.datasource.url=jdbc:h2:file:~/home/public/h2
for more details please check here ...