Saturn
Saturn

Reputation: 18149

Inspecting an H2 database while it is being used by Java

I am starting to develop with an H2 database in my server. I have a Java application that will be running all day long, using this database.

From time to time, I would like to inspect the contents of the database, with the H2 browser console. I couldn't help but notice that you can't have two simultaneous connections (one from my Java app and another from the browser console). This of course makes perfect sense.

It would seem like I have to shut down the Java temporarily so I can inspect my database. But I would rather not do that - at least not often (it's a multiplayer game server).

Now, my Java application has an user interface. I suppose I could program it to allow me to inspect the database using the connection it already has. I'm inclined to do that, unless there is a more convenient option.

Is there a way to inspect an H2 database using the browser console or something similar, even though it is being used already by a Java app?

Upvotes: 0

Views: 393

Answers (2)

user330315
user330315

Reputation:

The "Automatic Mixed Mode" is what you are looking for:

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

Quote from the manual:

Multiple processes can access the same database without having to start the server manually. To do that, append ;AUTO_SERVER=TRUE to the database URL [...] Use the same URL for all connections to this database. [...] The application that opens the first connection to the database uses the embedded mode, which is faster than the server mode

Upvotes: 1

Serge Ballesta
Serge Ballesta

Reputation: 149125

If you database is opened in embedded mode, only one JVM can get access to it. So you have two ways to do what you want :

  • gain access through your running application, by adding consulation screens, web service server functionality, ...
  • use your database in server mode, thus allowing concurrent accesses from different JVMs

Upvotes: 0

Related Questions