H2, Software Development, Spring Boot

Access Embedded in-memory H2 Used in Spring Boot

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.

in-memory H2 Spring Boot

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:

NOTE: Password is blank.

Logged In

With the web console, we can run SQL queries against available tables.

in-memory H2 Spring Boot

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.

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like