Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of SpringBoot Integrated in-memory Database hsqldb

Shulou Source: shulou.com Published: 2022-06-03 16:16:34 10月03日 Update

This article introduces you SpringBoot integrated memory database hsqldb example analysis, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Integrate the main memory database hsqldb. SpringBoot.

Why

Such as H2, hsqldb, derby, sqlite, such as in-memory database, small and lovely, do small server demo program, very easy to use. The most important feature is that you do not need to install another database.

Operation steps

Modify the pom.xml file

Org.hsqldb hsqldb

Modify the project configuration file application.yml

Spring: datasource: username: hsp password: 123456 url: jdbc:hsqldb:mem://localhost/blogdb;shutdown=true driver-class-name: org.hsqldb.jdbcDriver schema: classpath:schema.sql data: classpath:data.sql initialization-mode: always continue-on-error: true

Add initialization data file

Table creation script: schema.sql

CREATE TABLE blog (id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1) NOT NULL PRIMARY KEY, title varchar (255) DEFAULT NULL,)

Import data script: data.sql

Insert into blog (id,title) values (1pm 'Peanut skin programming blog')

Startup class: HspApplication

MapperScan ({"cn.hsp.blog"}) @ SpringBootApplicationpublic class HspApplication {public static void main (String [] args) {SpringApplication.run (HspApplication.class, args);}}

Controller class: BlogController

RestController@RequestMapping ("/ blog") public class BlogController {@ Autowired private BlogMapper blogMapper; @ GetMapping (value= "/ query") public List query () {return blogMapper.query ();}}

Mapper class: BlogMapper

Repositorypublic interface BlogMapper {@ Select (value = "select * from blog") List query ();}

Data bean:Blog

@ Datapublic class Blog {private int id; private String title;} project screenshot

Running

Just run HspApplication.

On the SpringBoot integrated memory database hsqldb example analysis is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Data database memory files examples analysis content more scripts help run good cute small maximum interest blog guy buddy just Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Technology MySQL Docker Xiaomi