Connect H2 from Spring Boot to database in Intellij

Connect H2 from Spring Boot to database in Intellij

Intellij (Ultimate Only) has the Database connection option to add database connection , however while connecting in-memory database like H2 (here part of Spring Boot) often we get problem .

  1. Solution Steps
    1. Set up Application .properties file
    2. Setup the Database
  2. Result

Solution Steps

Set up Application .properties file

  • make sure that you have provided url and set ddl-auto to update
spring.h2.console.enabled=true
server.port=9090
spring.datasource.url=jdbc:h2:./db/testDb;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE
spring.jpa.hibernate.ddl-auto=update

Setup the Database

  • Click on plus sign on Database tab (Usually situated on the right side of the system)
    • Click datasource from url

/assets/ConnectH2toInteliijDb/Untitled.png

  • Update following data as following , update credentials as per your usecase.

/assets/ConnectH2toInteliijDb/Untitled%201.png

Result

  • Resulting would be that your tables will be shown inside ‘Public’ , as shown below

/assets/ConnectH2toInteliijDb/Untitled%202.png