Can't see my H2 database in Web Console

不问归期 提交于 2019-12-04 00:50:14

问题


I created a H2 database with my code with this URL:

jdbc:h2:C:/data/fixed.db

My code can create tables, perform queries. If I open the file manually, I can successfully see its content and view the create queries etc

However, when I try to use H2 console with the web interface, I can't see the database. Instead, the web console create another empty database located here C:/data/fixed.db.mv.db. I just can't load my database.

What am I missing ?

EDIT

My code uses H2 1.3.175
The web console H2 1.4.178


回答1:


Finally I solved my problem...

Since 1.4.x, H2 uses MV_STORE (see SO answer here and Thomas Mueller comment). Apparently, the web console tries to append automatically a .mv.db extension. Even if there is already a file with the h2.db extension.

So , I upgrade the H2 version of my code from 1.3.175 to 1.4.178 and finally, I can see my data...

EDIT
Here is an alternative solution proposed by @devdanke:

You must manually tell your H2 1.4.x not to use MV_Store: ";mv_store=false". What a hassle.

For example, you would end with a code similar to:

Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection( //
    "jdbc:h2:file:C:\\my\\java\\projects\\test;mv_store=false" //
);



回答2:


I don't think .db is required in jdbc:h2:C:/data/fixed.db

I used this two lines and it worked fine for me

Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:file:G:\\projects\\test;MODE=MySQL;INIT=RUNSCRIPT FROM '~/test.sql'\\;");

My code just created a db file-format by the name test.mv.db



来源:https://stackoverflow.com/questions/24401635/cant-see-my-h2-database-in-web-console

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