Wednesday, May 2, 2018

How to Use H2 Embedded database in spring boot

H2 database is a inmemory data base which is embedded and we can use it as in memory database. it is quiet easy to use H2 database if you are working with small scale application when you just need to dumb data in db and use it later in the computation.

Advantage of using H2
  • It will not used application memory and will use the separate memory on same host.
  • It is less cheaper to use than database which are not in memory.( network databases are expensive in term of speed ) when there are not much data need to store.
Now let see the implementation of H2 Database in spring boot
You can download the project from GitHub
Lets first see the project structure

Now if we see the pom.xml what all the dependency we have added in the project

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""


 <description>Demo project for Spring Boot</description>

  <relativePath /> <!-- lookup parent from repository -->





So we have add below dependency in project
  1. Spring- Web
  2. JPA
  3. H2 database

Now let see the what we have added in it to configure the H2 Database

# H2
# Datasource

Now there are new things we need to understand here
Here we can provide what path we want to give to see the H2 Console ex- /h2-console , /h2
if this value will be true then only we will be able to see the H2 Console in browser.

Now let see how to access the H2 Console 
- Once you run the spring boot project , you can just go to the below url to see the h2 console.

When you hit this url you will be able to see the below screen
Note : Please ensure that the JDBC URL should be same as what you have mentioned in

After clicking on Connect button , you just see the below DB Console. when you can do all the operations.

That's all you need to do , Congratulations you are now using H2 database in your spring boot application.

Also Read:
  1. Spring Boot and Hibernate Tutorials - Application using Spring Boot
  2. What is Spring boot ?
  3. How to read value from property file in spring boot ?
  4. First Rest API Application - Top Spring Framework Interview Questions
  5. Implementation of Swagger in Spring boot
Hope this will help you in using H2 in spring boot.

Please share it with your friends and colleagues .

Thanks for reading


Post a Comment