Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

H2 connection fails

I'm trying to connect to a local H2 database, using the simple code :

    Class.forName("org.h2.Driver");
    Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");

On the other hand, I also connect to a distant Oracle server with its own jdbc driver. In my understanding, both can live together since the jdbc drivers are different and the correct one is used depending on the connection url. So this should not be the source of my problem.

It fails with the following error :

org.h2.jdbc.JdbcSQLException: File corrupted while reading record: "[16] stream data key:7 pos:11 remaining:0". Possible solution: use the recovery tool [90030-190]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
    at org.h2.message.DbException.get(DbException.java:179)
    at org.h2.message.DbException.get(DbException.java:155)
    at org.h2.index.PageBtreeIndex.getPage(PageBtreeIndex.java:156)
    at org.h2.index.PageBtreeIndex.<init>(PageBtreeIndex.java:69)
    at org.h2.table.RegularTable.addIndex(RegularTable.java:234)
    at org.h2.store.PageStore.addMeta(PageStore.java:1738)
    at org.h2.store.PageStore.readMetaData(PageStore.java:1637)
    at org.h2.store.PageStore.recover(PageStore.java:1405)
    at org.h2.store.PageStore.openExisting(PageStore.java:367)
    at org.h2.store.PageStore.open(PageStore.java:288)
    at org.h2.engine.Database.getPageStore(Database.java:2464)
    at org.h2.engine.Database.open(Database.java:672)
    at org.h2.engine.Database.openDatabase(Database.java:269)
    at org.h2.engine.Database.<init>(Database.java:263)
    at org.h2.engine.Engine.openSession(Engine.java:65)
    at org.h2.engine.Engine.openSession(Engine.java:175)
    at org.h2.engine.Engine.createSessionAndValidate(Engine.java:153)
    at org.h2.engine.Engine.createSession(Engine.java:136)
    at org.h2.engine.Engine.createSession(Engine.java:28)
    at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:349)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:107)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:91)
    at org.h2.Driver.connect(Driver.java:72)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)

I can still connect using the web console that runs on port 8082.

like image 249
Kristof Avatar asked Oct 31 '25 15:10

Kristof


1 Answers

Well, I found out how to solve my problem : change the connection url to

"jdbc:h2:tcp://localhost/~/test"
like image 89
Kristof Avatar answered Nov 03 '25 07:11

Kristof



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!