When we use an embedded in-memory H2 database with Spring Boot, we can access the data via H2’s web console. If we use Spring Security, we need to exclude the /h2-console URL from the authentication process.
You also need to set this property:
NOTE: Please be aware that this configuration is not ideal for production. H2 is generally suitable for creating prototypes.
In-Memory H2 Web console
Assuming we deployed our web application in http://localhost:8080, we can access the H2 console via the following URL.
You will be redirected to a login page.
Although we are using an in-memory H2, we still need a JDBC URL which in this case is the following. Also, we need to use a specific driver class which we need to specify as part of the JDBC connection string.
Viewing the Data Without Running Spring Boot
The default User Name and Password are:
User Name: sa
NOTE: Password is blank.
With the web console, we can run SQL queries against available tables.
That’s how we can access data in an in-memory H2 we use with Spring Boot. However, we typically use a better tool than the H2 web console. For example, we can use Jetbrain’s DataGrip or other SQL editors on our local machines.