Programmatically stop H2 database

Suppose we have a database H2that runs from a web application in Tomcatusing Hibernate. In other words, it is an embedded database H2in the application .

Question: is it possible to programmatically stop this server H2from this application, and then start it again?

Postscript Server.createTcpServer(args).start();or Server.shutdown(...)not, because it is in embedded mode.

+5
source share
1 answer

In this particular case, such an approach would be an acceptable solution:

  1. To stop the H2 database, simply use the SHUTDOWNsql command :

    session.createSQLQuery("SHUTDOWN").executeUpdate();

  2. H2, : Tomcat .

+11

All Articles