by Hayri Cicek
H2 is an open source relational database management system written in Java.
It can be embedded in Java applications or run in the client-server mode and it is easy to install and deploy.
Tools You Will Need
Your favorite IDE. I'm using NetBeans
Creating the Project With Spring Initializer
Go to start.spring.io and follow the steps below to generate a new project.
Enter the Details as Follows
Group: com.kodnito Artifact: spring-boot-with-h2 Dependencies: Web, H2, JDBCClick Generate Project to generate and download your project.
Create Schema and Data
spring.h2.console.enabled=true spring.datasource.url=jdbc:h2:file:~/test spring.datasource.driver-class-name=org.h2.Driver
Let's populate some data, create /src/main/resources/data.sql
create table todo ( id integer not null, title varchar(255) not null, primary key(id) );
Now when you open H2 Console http://localhost:8080/h2-console, you will now see that the todo table is created and the data is populated.
insert into todo values(1, 'Learn more Spring Boot'); insert into todo values(2, 'Go buy milk');