Question

I have 2 H2 databases under 2 different locations

D:\test\activitiDB\activiti.h2.db
and
D:\myapps\jbpmDB\jbpmdb1.h2.db

In Hsql, I can specify an alias name to the databases in Hsql properties files and simply use the alias name in the JDBC URL like so:

jdbc:hsqldb:hsql://localhost:9001/myDB1

where the alias myDB1 actually points to some file location mentioned in the HSQL database.

Is it possible to use something similar in H2 database system?

So that I can access the H2 databases from a SQL client OR JAVA code by something like:

jdbc:h2:tcp://localhost:9092/jbpmdb1
OR
jdbc:h2:tcp://localhost:9092/activiti

Right now using the above URL shows this StackTrace in my SQL Client:

java.util.concurrent.ExecutionException: java.lang.RuntimeException: org.h2.jdbc.JdbcSQLException: Database "D:/apps/dumps/H2_DB/bin/activiti" not found [90013-172]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
    at org.h2.message.DbException.get(DbException.java:169)
    at org.h2.message.DbException.get(DbException.java:146)
    at org.h2.engine.Engine.openSession(Engine.java:54)
    at org.h2.engine.Engine.openSession(Engine.java:160)
    at org.h2.engine.Engine.createSessionAndValidate(Engine.java:139)
    at org.h2.engine.Engine.createSession(Engine.java:122)
    at org.h2.server.TcpServerThread.run(TcpServerThread.java:138)
    at java.lang.Thread.run(Unknown Source)

Thanks.

Was it helpful?

Solution

In H2, there is no alias mechanism as in HSQLDB. What you can do in H2 is set one base directory per server. If you need multiple base directories, you could start multiple server (on different ports), as follows:

java org.h2.tools.Server -tcp -tcpPort 9091 -baseDir D:\test\activitiDB
java org.h2.tools.Server -tcp -tcpPort 9092 -baseDir D:\myapps\jbpmDB
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top