首页 技术 正文
技术 2022年11月17日
0 收藏 328 点赞 5,081 浏览 1543 个字

1. Spring Boot下H2数据库的常用配置项

# 指定数据库的类型
spring.datasource.platform=h2# 数据库连接地址(文件模式)
## AUTO_SERVER=TRUE,启动自动混合模式,允许开启多个连接,该参数不支持在内存中运行模式
## DB_CLOSE_ON_EXIT=FALSE,当虚拟机退出时并不关闭数据库
spring.datasource.url=jdbc:h2:file:./h2/code-generator;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE
## 内存模式示例
# spring.datasource.url=jdbc:h2:mem:testdb# 数据库驱动
spring.datasource.driver-class-name=org.h2.Driver# 用户名
spring.datasource.username=testdb# 密码
spring.datasource.password=test# 是否启用H2控制台
spring.h2.console.enabled=true# H2控制台的访问路径, 缺省是/h2-console
spring.h2.console.path=/h2-console# 是否允许远程访问H2
spring.h2.console.settings.web-allow-others=true

关于连接URL中的DB_CLOSE_ON_EXIT=FALSE

Don’t Close a Database when the VM Exits.

By default, a database is closed when the last connection is closed. However, if it is never closed, the database is closed when the virtual machine exits normally, using a shutdown hook. In some situations, the database should not be closed in this case, for example because the database is still used at virtual machine shutdown (to store the shutdown process in the database for example). For those cases, the automatic closing of the database can be disabled in the database URL. The first connection (the one that is opening the database) needs to set the option in the database URL (it is not possible to change the setting afterwards).

2. h2的内存模式与本地模式

本地文件模式

spring.datasource.url=jdbc:h2:file:~/testdb

该例子中的~是用户目录。

内存模式

spring.datasource.url=jdbc:h2:mem:testdb

内存模式时,应用关闭则数据库同时关闭,数据库中的数据也就清空了。

3. H2的控制台

控制台界面如下:

端口号

访问H2的控制台时,URL中的端口号就是所在应用的端口号

路径

访问H2的控制台的路径后缀是spring.h2.console.path配置项的值,默认是/h2-console

Driver Class

org.h2.Driver

JDBC URL

填配置项spring.datasource.url的值

用户名密码

application.properties中配置的值对应。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,133
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297