Setting up the H2 Database

Learn how to connect to the in-memory H2 database, create tables, and populate data.

In this lesson, we will set up the in-memory H2 database. Let’s have a look the required steps:

Configuring database connection

  • The in-memory database H2 has automatically been configured in our application. The URL of the database can be found from the console log. This value is randomly generated each time the server is restarted. To make the database URL a constant, we need to configure this in application.properties as follows:

spring.datasource.url=jdbc:h2:mem:testdb
Setting up the H2 base URL in application.properties file
  • The next task is connecting to the H2 database. One of the reasons for using Spring Boot is that its autoconfiguration ...

Access this course and 1400+ top-rated courses and projects.