Accessing H2 Memory Database Remotely

2,119 views
Skip to first unread message

leojhartiv

unread,
Jun 18, 2009, 8:31:20 AM6/18/09
to H2 Database
I am currently a user of HSQLDB and am trying to upgrade to H2 in
order to better support our integration testing effort.

I have successfully deployed our application using H2, specifying the
following database information:

Driver=org.h2.Driver
url=jdbc:h2:mem:DBSHR
username=sa
password=

Now my goal is to run some integration tests, remotely accessing the
same database from a different JVM. I'm assuming this is possible
from this section of the documentation:

http://www.h2database.com/html/features.html#memory_only_databases

"It is also possible to access a memory-only database remotely (or
from multiple processes in the same machine) using TCP/IP or SSL/TLS.
An example database URL is: jdbc:h2:tcp://localhost/mem:db1 ."

I've tried connecting using the same JDBC configuration:

Driver=org.h2.Driver
url=jdbc:h2:mem:DBSHR
username=sa
password=

That doesn't seem to connect it to the existing database.

I've then tried connecting using the TCP configuration as suggested in
the documentation:

Driver=org.h2.Driver
url=jdbc:h2:tcp://localhost/mem:DBSHR
username=sa
password=

That gives me the following error message:

ERROR: An error occurred while trying to make a connection to
the database:

JDBC URL: jdbc:h2:tcp://localhost/mem:dbshr

Connection
is broken [90067-114]

Is there a step I'm missing?

I'm currently working with H2 version 1.1.114, Spring 2.5.5 and
Hibernate 3.2.6.GA.

I've tried simulating the same functionality using RazorSQL: I opened
one session using the first JDBC settings and then opened a new
instance of RazorSQL, opening another session using the second JDBC
settings. I receive the same error message.

Any assistance you can provide is appreciated!

sim

unread,
Jun 20, 2009, 3:54:20 PM6/20/09
to H2 Database
To access your database remotely you should add a line in wrapper.conf
file

wrapper.app.parameter.x=-tcpAllowOthers where
x - parameter number




leojhartiv

unread,
Jun 22, 2009, 3:52:52 PM6/22/09
to H2 Database
Where is this file located? I'm using H2 embedded in my WAR
file...it's in memory only.

Thomas Mueller

unread,
Jun 22, 2009, 11:43:24 PM6/22/09
to h2-da...@googlegroups.com
Hi,

> Now my goal is to run some integration tests, remotely accessing the
> same database from a different JVM.  I'm assuming this is possible
> from this section of the documentation:
>
> http://www.h2database.com/html/features.html#memory_only_databases

> Is there a step I'm missing?

You also need to start a server, specially a "TCP server":
http://www.h2database.com/html/tutorial.html#using_server

This is the "Server Mode":
http://www.h2database.com/html/features.html#connection_modes

> I'm using H2 embedded

No, it looks like you are using the server mode, not the embedded mode.

Regards,
Thomas

leojhartiv

unread,
Jun 23, 2009, 8:43:03 AM6/23/09
to H2 Database
Well, I guess I'm not sure what mode I need.

I'm currently using H2 in embedded memory-only mode. I use this in
spring/hibernate-wired integration tests. I also use it embedded,
memory-only on developer desktops: they fire up the application
locally during development for smoke testing vs starting it with our
production database, Oracle.

Now I have a need to run web integration tests when the application is
running. So a developer would:

1. Start tomcat and the web application using the memory-only,
embedded database.
2. Run web integration tests via Maven using Sellenium WebTest. These
tests would need access to the database used by the web application
(in this case its embedded memory-only H2 instance) in order to seed
the application with data prior to each test.

From the documentation, I assumed this was possible. Perhaps it's not
though...




On Jun 22, 11:43 pm, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:

leojhartiv

unread,
Jun 25, 2009, 4:23:52 PM6/25/09
to H2 Database
I finally figured out what you meant...I read it wrong the first time.

I'm able to remotely connect to my mem db now.

Thanks for your help!
Reply all
Reply to author
Forward
0 new messages