我们正在开发一个Play 2.4应用程序(Java API)。
出于开发目的,我们希望使用一个持久的H2数据库,该数据库具有相对于项目根目录的DB文件路径。
在How to use a persistent H2 database in the Play Framework instead of in-memory中有Play 2.0的解决方案:
db.default.url="jdbc:h2:file:data/db"
然而,在Play 2.4中,这似乎不起作用,但我得到了错误消息,底部有以下异常:
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:data/db". Use an absolute path, ~/name, ./name, or the
baseDir setting instead. [90011-187]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
...
我可以让连接使用绝对路径和相对于主目录的相对路径,如下所示:
db.default.url="jdbc:h2:file:/Users/foo/data/db"
或
db.default.url="jdbc:h2:~/data/db"
但是,有什么方法可以引用项目根文件夹吗?
发布于 2015-06-03 14:41:47
好的,我做了一些研究,在changelog (http://www.h2database.com/html/changelog.html)中找到了这个:
测试隐式相对路径被禁用(系统属性“h2.implicRelativePath”),因此数据库URL jdbc:h2:
现在需要写成jdbc:h2:./test。
从1.4.177测试版开始的H2中,不再允许隐式相对路径。因此,在您的示例中,url应该使用显式的相对路径编写:db.default.url="jdbc:h2:./data/db"
。
发布于 2018-12-27 08:55:28
可以使用固定路径或相对路径。当使用URL jdbc:h2:file:./data/sample http://www.h2database.com/html/faq.html时
现在可以使用相对路径了。
例如,jdbc:h2:file:./../../h2db;
https://stackoverflow.com/questions/30596150
复制相似问题