In-memory Database: H2

You’re never too old to learn

I use H2 as a database when I refresh my knowledge about JPA (Java Persistence API). Therefore, I think to write a little bit about H2 database and how to use H2 as a database in your Spring Boot application.

Note: A purpose of this post is to help me review what I have learned. As I am old and start to have bad memories.

What is H2?

H2 is a relational database management system written in Java.

Enable H2 database in Spring Boot application

  <groupId>com.h2database</groupId>
  <artifactId>h2</artifactId>
  <scope>runtime</scope>

Enable H2 console

Configure the following properties in application.properties at src/main/resources

# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2

Persistent, embedded database

Configure the following properties in application.properties

# Datasource
spring.datasource.url=jdbc:h2:file:~/test
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: