Connect to H2 database using IntelliJ database client

馋奶兔 提交于 2019-11-28 18:33:16

Your configuration is for an h2:mem database. Memory Databases have no tables upon connecting to them, and any & all tables are lost when all the connections are closed. Furthermore, a (named) in memory database is unique to the JVM process that opens it. From the H2 documentation:

Sometimes multiple connections to the same in-memory database are required. In this case, the database URL must include a name. Example: jdbc:h2:mem:db1. Accessing the same database using this URL only works within the same virtual machine and class loader environment. (Emphasis added)

This means IDEA will create a unique devDb in its JVM (and classloader) space and your application will create a unique devDb in its JVM (and classloader) space. You can not connect to an in memory database from an external JVM process.

If you want to connect both your application and IntelliJ IDEA (or any other DB tool) to an H2 database at the same time, you will need to either

  1. use an embedded database (that writes to a file) in your application and use Mixed Mode to allow IntelliJ IDEA (and/or other database tools) to connect to it
  2. use a server mode database

See http://www.h2database.com/html/features.html#connection_modes for more information.

This article has a great write up on how to set up the IntelliJ database client to connect to an H2 in-memory database if you happen to be using Spring Boot: https://techdev.io/en/developer-blog/querying-the-embedded-h2-database-of-a-spring-boot-application

Basically, you wrap the in-memory database with a tcp server, then you have an access point to connect with a sql client via remote access.

During development you can use grails h2 dbconsole

Try to open http://localhost:8080/dbconsole and fill your jdbc url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!