Stephan
Stephan

Reputation: 43083

Can't see my H2 database in Web Console

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

Upvotes: 8

Views: 9974

Answers (2)

Stephan
Stephan

Reputation: 43083

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" //
);

Upvotes: 6

SparkOn
SparkOn

Reputation: 8956

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

Upvotes: 0

Related Questions