Displaying an H2 in-memory database on the web with Spring Boot
Since it is troublesome to build a RDB, the H2 database is in-memory, so it is very convenient because it can be used out of the box with only dependencies.
If you place schema.sql under “src/main/resources/”, you can create tables in advance.
If data.sql is placed under “src/main/resources/”, data can be created in advance.
Add the following two dependencies to build.gradle.
developmentOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'com.h2database:h2'
Next, add a setting to application.yml.
spring: datasource: url: jdbc:h2:mem:testdb # In this case, I used a schema called testdb. driverClassName: org.h2.Driver h2: console: enabled: true path: /h2-console
This will launch the Spring Boot application.
After launching, access “http://localhost:8080/h2-console/” and you will see the following screen.
Press “Connect” to see the screen as shown below.
This screen also allows for operations such as Select and Insert statements.
コメント