I am trying to convert my existing embedded H2 database and enable external connections to it. Currently my properties are
spring.datasource.url=jdbc:h2:file:./db;AUTO_SERVER=TRUE;AUTO_SERVER_PORT=9090 spring.datasource.driverClassName=org.h2.Driver spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.h2.console.enabled=true spring.h2.console.path=/h2 spring.h2.console.settings.web-allow-others=true server.ssl.enabled=true server.ssl.key-store-password=#### server.ssl.key-password=### server.ssl.key-store-type=JKS etc
For a local connection to my db in this mode I seem to be able to connect to “jdbc:h2:file:./db;AUTO_SERVER=TRUE;AUTO_SERVER_PORT=9090” through my intellej IDE.
If this database is hosted on a external server how do i connect to it? I have tried putting the hostname into this URL such as at jdbc:h2:file:123.456.789.10/db;AUTO_SERVER=TRUE;AUTO_SERVER_PORT=9090 But it is unable to connect.
You need to launch a separate H2 Server process on the host where you want to store your database files. https://h2database.com/html/tutorial.html#using_server
After that you will be able to use remote connections to it with remote URLs: https://h2database.com/html/features.html#database_url You need also to remove H2 console from your application, you will be able to use web interface of the server instead.
Don’t forget to enable remote access via TCP and web port on the server. You should also guard your server with firewall to prevent access from untrusted hosts. H2 is not a secure container, database users with
ADMIN privileges have full access to the system by design as server’s account and possibly the security manager allows.
AUTO_SERVER cannot work over network.