h2 (embedded mode ) database files problem

假装没事ソ 提交于 2019-11-27 14:41:38

For embedded mode, you'll need to check the path. For example, use a path relative to your home directory:

"jdbc:h2:file:~/db/h2test.db"

To be sure, use a full path:

"jdbc:h2:file:/users/aeter/db/h2test.db"

For convenience, append ;IFEXISTS=TRUE to avoid creating spurious database files.

See Connecting to a Database using JDBC for more.

H2 Server URLs are relative to the -baseDir specified as a parameter to main().

Also there can be a problem if you use some special parameters in your JDBC url, the database file name can differ for various cases.

In my case, I had two URLs:

  • jdbc:h2:~/XXX;MVCC=FALSE;MV_STORE=FALSE
  • jdbc:h2:~/XXX

This first case created XXX.h2.db file, the second one XXX.mv.db, beware.

Also you can like this

"jdbc:h2:file:db/h2test.db"

then java looks db folder from project folder

->projectName // project folder
-->src        // src folder
-->db         // here your database folder
-->....

If you are using Hibernate try this in hibernate.cfg.xml file:

<property name="connection.url">jdbc:h2:file:db/h2test</property>

without *.db extension at the end

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!