Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of SpringBoot Integrated in-memory Database hsqldb

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report