Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

H2 Database Auto Server mode : Accessing through web console remotely

Tags:

java

scala

h2

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.

like image 234
Yadu Krishnan Avatar asked Mar 22 '26 19:03

Yadu Krishnan


1 Answers

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

like image 162
Saif Asif Avatar answered Mar 25 '26 09:03

Saif Asif



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!