Which version of H2 database geodb works with?

613 views
Skip to first unread message

Lukasz

unread,
Aug 15, 2010, 12:51:10 PM8/15/10
to geodb
Jan, everyone,

I can create and manipulate spatial data in H2 using geodb with no
problems - but only when I run it using the 'geodb' application. When
I connect to the database created by geodb using the 'normal' H2
console, I' m getting 'Unsupported database file version or invalid
file header in file "Old database: /tmp/h2db-test.data.db - please
convert the database to a SQL script and re-create it."' exception.

Does it still mean that I can run the H2 database with geodb spatial
extensions as an embedded database?

Greetings,

Lukasz

Jan Boonen

unread,
Aug 16, 2010, 2:51:50 AM8/16/10
to geodb
Hi Lukasz,

You can still run GeoDB as an in-memory database that uses the H2
driver. The 'trick' is to set up a H2 in-memory database and then call
the static method GeoDB.InitGeoDB(Connection conn).

Code example:

DriverManagerDataSource dataSource = new DriverManagerDataSource();
// use the H2 JDBC driver
dataSource.setDriverClassName("org.h2.Driver");
// have it create an database in users's home directory
dataSource.setUrl("jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1");
dataSource.setUsername("sa");
dataSource.setPassword("sa");
// initialize datasource (ddl, test data, etc.)
Connection cx = dataSource.getConnection();
try
{
// spatially enable
GeoDB.InitGeoDB(cx);
...

This works very well for the integration tests that we use here at
Geodan. Hope the example will work for you as well. If you use Spring
for your integration tests, consider using the test factory that is in
my public github repository: http://github.com/boonen/GeoDBTestDataSourceFactory

Cheers,

Jan
Reply all
Reply to author
Forward
0 new messages