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

How to use H2 embedded Database in SpringBoot

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

Share

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

Xiaobian to share with you how SpringBoot uses H2 embedded database, I believe most people still do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

1. Add maven dependency

com.h3database h3

Add configuration information to application.properties.

spring.datasource.driverClassName=org.h3.Driver#Connection information database file save location (embedded)#~ indicates current user directory C:\Users\Administrator#spring.datasource.url=jdbc:h3:~/test;MODE=MYSQLspring.datasource.url=jdbc:h3:E:/h4/test;MODE=MYSQL#spring.datasource.url=jdbc:h3:file:./ dbconfig/test; MODE=MYSQLspring.datasource.username=rootspring.datasource.password=root#Do you want to open console spring.h3.console.enabled=true#Console path spring.h3.console.path=/h3

3. Start

2021-10-30 19:51:50.011 INFO 5952 --- [ main] o.s.b.a.h3.H2ConsoleAutoConfiguration : H2 console available at '/h3'. Database available at 'jdbc:h3:E:/h4/test'

2021-10-30 19:51:50.868 INFO 5952 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 80 (http) with context path ''

2021-10-30 19:51:50.879 INFO 5952 --- [ main] com.example.DemoApplication : Started DemoApplication in 3.336 seconds (JVM running for 3.657)

At this point you will see the file generated.

.mv is a data file.trace is a log file

We can open the browser http://localhost/h3/

4. Integration project packaging

Modify connection paths

#./ dbconfig/test The test database in the dbconfig folder under the current project path spring.datasource.url=jdbc:h3:file:./ dbconfig/test;MODE=MYSQL

packaged

org.springframework.boot spring-boot-maven-plugin maven-resources-plugin copy-dbconfig package copy-resources dbconfig ${project.build.directory}/dbconfig

And then it's ready to go.

The above is "SpringBoot how to use H2 embedded database" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

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