Monday, April 11, 2016

H2 Database Auto Server mode : Accessing through web console remotely

Leave a Comment

I am fairly new to H2 Database. As a part of a PoC, I am using H2 database(version : 1.4.187) for mocking the MS SQL Server DB. I have one application, say app1 which generates the data and save into H2. Another application, app2, needs to read from the H2 database and process the data it reads. I am trying to use Auto Server mode so that even if one of the application is down, other one is able to read/write to/from the database.

After reading multiple examples, i found how to build the h2 url and shown as below:

jdbc:h2:~/datafactory;MODE=MSSQLServer;AUTO_SERVER=TRUE; 

Enabled the tcp and remote access as Below:

org.h2.tools.Server.createTcpServer("-tcpAllowOthers","-webAllowOthers").start() 

With this, I am able to write to the database. Now, I want to read the data using the h2-web-console application. I am able to do that from my local machine. However, I am not able to understand how I can connect to this database remotely from another machine.

My plant is to run these two apps in an ubuntu machine and I can monitor the data using the web console from my machine. Is it not possible with this approach? How can I solve this ?

Or do I need to use server mode and explicitly start the h2 server? Any help would be appreciated.

2 Answers

Answers 1

By default, remote connections are disabled for H2 database for protection. To enable remote access to the TCP server, you need to start the TCP server using the option -tcpAllowOthers or the other flags -webAllowOthers, -pgAllowOthers .

To start both the Web Console server (the H2 Console tool) and the TCP server with remote connections enabled, you will have to use something like below

java -jar /path/to/h2.jar -web -webAllowOthers -tcp -tcpAllowOthers -browser 

More information can be found in the docs here and console settings can be configured from here

Answers 2

Not entirely sure but looking at the documentation and other questions answered previously regarding the same topic the url should be something like this:

jdbc:h2:tcp://<host>:<port>/~/datafactory;MODE=MSSQLServer;AUTO_SERVER=TRUE; 

It seems that the host may not be localhost and the database may not be in memory

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment