Skip to content

Latest commit

 

History

History
55 lines (31 loc) · 2.82 KB

h2-database.md

File metadata and controls

55 lines (31 loc) · 2.82 KB

H2 Database

When running on localhost, this code base uses a temporary database built on a technology called H2.

An H2 database is not necessarly suitable for a production application; it may not handle concurrent access with good performance, for example. But for testing purposes, it's just fine, and has some advantages:

  • you don't have to manage a separate server process (all of the code is built-in to the Spring Boot framework)
  • you don't have to install a separate database on your system (e.g. Postgres, MySQL, etc.)

Resetting the Database

The temporary database is stored in the target directory, so any time you do a mvn clean operation, that database is wiped away so that you can start from scratch.

This is both good and bad; the key thing is to be aware of this.

The H2 Console

It isn't necessarily a course goal for you to become fully proficient in SQL (Structured Query Language, the language used to manipulate databases.)

But a little SQL can go a long way, and it can sometimes be helpful to peek under the hood at the database to see what's going on.

When running on localhost, an H2-Console can be accessed from the menu bar.

H2-Console button

When you click on H2-Console, you get a page like this one:

H2 console login prompt

The username/password are set in the file src/main/resources/application-development.properties, for example:

spring.datasource.username=sa
spring.datasource.password=password`

Note that the value password for a password is of course a terrible choice; but keep in mind that this is only for localhost testing, which is by definition not avaiable on the public internet, so security here is not a primary concern. When deploying on Heroku, an entirely different database system and password management system is in place.

Once you enter the username and password and press Connect, you may see a warning like this about the password password, which is probably fine to ignore. If it annoys you, perhaps choose a different random (but not one that you use for any other system!)

warning about password

After that, you should see a page that looks like this. We will leave it to you to discover the things you can do here. An SQL tutorial may help; a good one can be found here: https://www.w3schools.com/sql/

image