Reputation: 717
I'm doing a simple Spring Boot & embedded H2 tutorial with Eclipse/STS on a MacBook.
It works fine when I use H2 as memory only, my application.properties
file looks like this:
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
But I want to persist the database to a file (so that the data is not lost when app is shut down).
When I make this change to write DB to the disk:
spring.datasource.url=jdbc:h2:file:/data/demo
I get this error on startup:
org.h2.message.DbException: Log file error: "/data/demo.trace.db", cause: "org.h2.message.DbException: Error while creating file ""/data"" [90062-200]" [90034-200]
What am I doing wrong?
More details from the stack trace:
2020-11-09 12:33:24.246 INFO 15139 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
org.h2.message.DbException: Log file error: "/data/demo.trace.db", cause: "org.h2.message.DbException: Error while creating file ""/data"" [90062-200]" [90034-200]
org.h2.message.DbException: Log file error: "/data/demo.trace.db", cause: "org.h2.message.DbException: Error while creating file ""/data"" [90062-200]" [90034-200]
at org.h2.message.DbException.get(DbException.java:194)
at org.h2.message.TraceSystem.logWritingError(TraceSystem.java:294)
[...]
Caused by: org.h2.jdbc.JdbcSQLNonTransientException: Log file error: "/data/demo.trace.db", cause: "org.h2.message.DbException: Error while creating file ""/data"" [90062-200]" [90034-200]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:505)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
... 92 more
Caused by: org.h2.message.DbException: Error while creating file "/data" [90062-200]
at org.h2.message.DbException.get(DbException.java:205)
at org.h2.message.DbException.get(DbException.java:181)
at org.h2.store.fs.FilePathDisk.createDirectory(FilePathDisk.java:290)
at org.h2.store.fs.FileUtils.createDirectory(FileUtils.java:43)
at org.h2.store.fs.FileUtils.createDirectories(FileUtils.java:315)
at org.h2.message.TraceSystem.openWriter(TraceSystem.java:305)
... 89 more
Caused by: org.h2.jdbc.JdbcSQLNonTransientException: Error while creating file "/data" [90062-200]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:505)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
... 95 more
Upvotes: 5
Views: 8219
Reputation: 717
The solution was I needed a .
like this ./data/demo
:
spring.datasource.url=jdbc:h2:file:./data/demo
Upvotes: 21