SQLException: invalid database address (works the first time)

1,256 views
Skip to first unread message

gonfi

unread,
Nov 27, 2013, 3:45:54 PM11/27/13
to h2-da...@googlegroups.com
using version 1.3.166, also tried latest 1.3.174, same behavior.

i'm running unit tests with spring. each test class sets up spring and creates a single connection to a specific h2 database file.
the first connection works fine.
using a testng @AfterClass i close the single connection. i assert that the connection is closed afterwards.
from the 2nd class on i get this exception:

java.sql.SQLException: invalid database address: jdbc:h2:file:c:\path\mydb;IFEXISTS=TRUE;ACCESS_MODE_DATA=r

the database c:\path\mydb.h2.db exists of course, otherwise the first connection would fail already.

my h2 database files are 3 to 10 GB each.

my questions:

1) how's that possible? i can't find anything on google about this exception.

2) how would one run unit tests with junit or testng and close and re-open the same db (not in-memory, not dropping)? i can't find anything about that. the manual just says when the jvm exits (which is not the case when running a test suit). or closing the last connection. what if someone opens multiple connections, how would he force a close? (i have just one connection).

3) i have tried with and without FILE_LOCK=NO. either way there are no file locks. makes sense since it's read only... but why would it not let me connect again anyway when it's read-only? can't do any harm, can it?

Noel Grandin

unread,
Nov 28, 2013, 2:11:29 AM11/28/13
to h2-da...@googlegroups.com


On 2013-11-27 22:45, gonfi wrote:
>
> java.sql.SQLException: invalid database address: jdbc:h2:file:c:\path\mydb;IFEXISTS=TRUE;ACCESS_MODE_DATA=r
>

That error message is not coming from H2, so I suspect that your test framework has a bug somewhere.

gonfi

unread,
Nov 29, 2013, 8:21:19 PM11/29/13
to h2-da...@googlegroups.com
you're right. i was able to solve it.

the exception came for the sqlite driver.
the JDK's ConnectionManager tried all loaded drivers. all of them returned null (can't connect), except for the one from sqlite, which threw that particular exception. the ConnectionManager, after trying all and none succeeded, re-threw that exception

i had used some wrapper around the h2 connection driver. after removing that magic, all worked fine.
Reply all
Reply to author
Forward
0 new messages