Over a million developers have joined DZone.

Share an h2 in-memory database among several JVMs

· Java Zone

Easily build powerful user management, authentication, and authorization into your web and mobile applications. Download this Forrester report on the new landscape of Customer Identity and Access Management, brought to you in partnership with Stormpath.

I hate when things are written in the docs but not clearly enough to understand it on the first time.

I wish I were the only one not to have get this right at first, but if you look in google for terms like

“share h2 database among applications”

“common h2 database among jvms”

“accessing in-memory database from another jvm”

you’ll find plenty of confused people too.

SO here is the explanation

Because you are writing some test or POC, you want to use an In-Memory Database.

H2 is cool, you can look at the tutorial and cook-up a config pretty fast and it works very well.

Then let’s say you want to share your database amongst different processes/JVMs. That’s when the documentation becomes unclear (although everything is explained there).

the first process is going to create the DB, with the following URL :


and it’s going to need to start a tcp Server

final String[] args = new String[] {
"-tcpPort", "8092",
"-tcpAllowOthers","true" };

org.h2.tools.Server server = org.h2.tools.Server.createTcpServer(args).start();

Of course do not forget to stop the server when you exit the application


The other processes can then access your DB by using the following URL:



From http://jsoftbiz.wordpress.com/2011/04/30/share-an-h2-in-memory-database-among-several-jvms/

Building Identity Management, including authentication and authorization? Try Stormpath! Our REST API and robust Java SDK support can eliminate your security risk and can be implemented in minutes. Sign up, and never build auth again!


The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}