Best Practice using H2

164 views
Skip to first unread message

mrbr...@gmail.com

unread,
Mar 23, 2021, 5:46:48 AM3/23/21
to H2 Database
A recent reply (https://groups.google.com/g/h2-database/c/lYi5Usc4tHU/m/yL1_dwA8AgAJ?pli=1) suggests that an application should not start the TCP server.  Is there any 'best practice' documentation concerning set up and use  of H2?
I am using H2 for a Java app (not web) and start the TCP server so I can access the database from outside the app. If I use the file based way of opening the DB it is locked from use by other processes, eg. the console. 
Can someone point me at any suggestions on the best way to do this.
Thanks

Evgenij Ryazanov

unread,
Mar 23, 2021, 6:17:09 AM3/23/21
to H2 Database
If you need the H2 Console only, you can embed it as a servlet into your application:
Don't forget to configure the security constraints to prevent access to it from untrusted and unauthorized users.

If you need to accept connections from other applications, you need to use the separate H2 server process, possibly running as a system service. Your web application and other applications need to use remote connections to it in that case.

Mike Bray

unread,
Mar 23, 2021, 7:47:19 AM3/23/21
to h2-da...@googlegroups.com
Thanks, I will do it as a file, the console is really only for debugging purposes. The user will not know about h2 and so shouldn’t need to access the db.
Regards
Mike

--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/ff81ab83-dbe9-4c99-a977-b7f1518a7b3dn%40googlegroups.com.

andreas

unread,
Mar 23, 2021, 8:37:36 AM3/23/21
to h2-da...@googlegroups.com
Mike.

For our own software we test if the h2 port is open. If not we start the h2 server per java api and stop it when the software exits.

When the port is found open we assume the h2 servers has been started externally and act as a client strictly.

This may not been best practise but works like a charm and reliable for us.

Best regards 



Sent from my Galaxy
Reply all
Reply to author
Forward
0 new messages