我有一个H2数据库文件,名为“ test.db”。该文件位于我的应用程序目录中:“ myApp / resources / test.db”。我无法为我工作,所以引用相对路径的正确方法是什么?
这是我的hibernate.cfg.xml的配置。
<property name="connection.driver_class">org.h2.Driver</property> <property name="connection.url">jdbc:h2:file:/test</property> <property name="connection.username">test</property> <property name="connection.password">1234</property> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.H2Dialect</property>
发生错误的是:
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:/test2". Use an absolute path, ~/name, ./name, or the baseDir setting instead. [90011-191]
您应该将URL编写为明确的相对路径: <property name="connection.url">jdbc:h2:file:./test</property>
<property name="connection.url">jdbc:h2:file:./test</property>