MULTI_THREADED=1 fails after LOCK_MODE=0, no exception

51 views
Skip to first unread message

Fabian Kessler

unread,
Mar 10, 2014, 4:14:54 PM3/10/14
to h2-da...@googlegroups.com
The situation: after a db import with the suggested (persistent) setting LOCK_MODE=0, connecting to the same or another db with the global setting MULTI_THREADED=1 fails.
One needs to reset the lock mode with LOCK_MODE=3.

This has been noted by https://groups.google.com/forum/#!msg/h2-database/chvHwUZ20xQ/sYgNWLVSUXQJ and it's the only place after 2 hrs of searching where I've found the solution.

The reason why I did not solve this quicker is because in my setup, I got an SQLException from sqlite instead:

java.sql.SQLException: invalid database address: jdbc:h2:file:c:/h2tempdb;
IFEXISTS=TRUE;ACCESS_MODE_DATA=r;MULTI_THREADED=1
    at org.sqlite.JDBC.createConnection(JDBC.java:110)
    at org.sqlite.JDBC.connect(JDBC.java:87)
    at java.sql.DriverManager.getConnection(DriverManager.java:579)
    at java.sql.DriverManager.getConnection(DriverManager.java:243)
    at com.optimaize.labs.dbperf.databases.h2.ConnectionTest.run(ConnectionTest.java:54)
    at com.optimaize.labs.dbperf.databases.h2.ConnectionTest.thisFails(ConnectionTest.java:26)

It seems that this happens when I have 2 sql drivers. Java asks each, all report they can't handle this connection string, and the last one (sqlite) throws this.
I've created a short reproducible test case here: https://github.com/fabiankessler/readonly-embedded-dbs-benchmark/blob/master/src/test/java/com/optimaize/labs/dbbench/databases/h2/ConnectionTest.java

Also, I'm wondering why LOCK_MODE=0 is not acceptable when my connection is ACCESS_MODE_DATA=r.

Thomas Mueller

unread,
Mar 11, 2014, 3:18:45 AM3/11/14
to H2 Google Group
Hi,

The reason why you got the exception "invalid database address:" from the SQLite JDBC driver is that the SQLite JDBC driver does not follow the JDBC specification. That means it is a bug in the SQLite JDBC driver. According to the JDBC specification, Driver.connect should return null for JDBC URLs it doesn't understand. From the JDBC API spec: "The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL. This will be common, as when the JDBC driver manager is asked to connect to a given URL it passes the URL to each loaded driver in turn. The driver should throw an SQLException if it is the right driver to connect to the given URL but has trouble connecting to the database."

Regards,
Thomas


--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database...@googlegroups.com.
To post to this group, send email to h2-da...@googlegroups.com.
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages