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.
答案 0 :(得分:3)
Well, I found out how to solve my problem : change the connection url to
"jdbc:h2:tcp://localhost/~/test"
答案 1 :(得分:0)
根据H2 Features • Database URL Overview,有许多可用的网址表达式,这里有一些例子:
jdbc:h2:~/test
jdbc:h2:file:/data/sample
jdbc:h2:file:C:/data/sample
(仅限Windows)jdbc:h2:mem:test_mem
jdbc:h2:tcp://localhost/~/test
jdbc:h2:tcp://dbserv:8084/~/sample
jdbc:h2:tcp://localhost/mem:test
还有其他许多人,请查看上面的链接以查看完整列表。