8

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

Stephan
  • 41,764
  • 65
  • 238
  • 329

2 Answers2

6

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" //
);
Community
  • 1
  • 1
Stephan
  • 41,764
  • 65
  • 238
  • 329
  • 2
    Many 3rd party database tools use H2 1.3.x because it's the stable version. Yet H2 1.4.x defaults to using the "beta", "experimental" MV_Store storage engine, which H2 1.3.x can't read. Because of H2's unfortunate default, you must manually tell your H2 1.4.x not to use MV_Store: ";mv_store=false". What a hassle. – devdanke Feb 24 '15 at 12:18
  • 2
    @devdanke your comment alone solved my problem, which was similar to the OP but until now I wasn't being able to solve it. Thanks a lot! ";mv_store=false" does the trick! – Joao Baltazar Oct 14 '15 at 13:19
  • Reading my comment a few years later, I regret the tone. I was annoyed by the H2 config default. But, more importantly I am thankful to Thomas Müller, his excellent H2 DB, and that he gives it to us for free. – devdanke Feb 04 '17 at 21:28
0

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

SparkOn
  • 8,806
  • 4
  • 29
  • 34