切换其他数据库
最后更新于:2022-04-02 07:08:52
数据库切换
===
>[info] 提供Oracle、SqlServer、Postgresql 切换具体配置文档
[TOC]
## 1. Oracle数据
### 1.1 添加oracle驱动,修改pom.xml
```
com.oracle
ojdbc6
11.2.0.3
```
### 1.2 修改数据库连接
```
修改druid配置
validationQuery: SELECT 1 FROM DUAL
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@192.168.1.200:1521:ORCL
username: jeecgboot
password: jeecgboot
```
## 2. SQL server数据
### 2.1 添加SQL server驱动,修改pom.xml
```
com.microsoft.sqlserver
sqljdbc4
4.0
runtime
```
### 2.2 修改数据库连接
```
修改druid配置
validationQuery: SELECT 1
filters: stat,slf4j
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://192.168.1.200:1433;SelectMethod=cursor;DatabaseName=jeecg-boot
username: sa
password: SA
修改JPA加上database-platform参数
jpa:
open-in-view: false
database-platform: org.hibernate.dialect.SQLServerDialect
```
### 2.3 sqlserver下定时任务报错处理
```
报错信息org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: sql injection violation, syntax error: syntax error, not support option : UPDATE, pos 86, line 1, column 80, token UPDATE
```
修改配置如下:将selectWithLockSQL: SELECT* FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?配置在jobStore下
```
quartz:
.....省略其他配置.....
properties:
org:
quartz:
jobStore:
selectWithLockSQL: SELECT* FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?
```
### 2.4 sqlserver下启动后,如果控制台一直滚动如下图信息
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/be/87/be873f33063df556245b47d3d248d469_1890x473.png)
可修改配置文件
```
web-stat-filter:
enabled:false
```
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/0b/0f/0b0f8771b0bfa379ed63c403c11f2722_236x53.png)
### 2.5 sqlserver启动失败,报错--- 不支持“variant”数据类型
修改sqlserver版本即可解决,将sqljdbc4替换为mssql-jdbc
~~~
com.microsoft.sqlserver
mssql-jdbc
8.2.2.jre8
~~~
报错信息:
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/f3/d5/f3d53ee4cbcb513bfb0747bf85d4f38d_1024x287.png)
修改依赖jar包:
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/bb/75/bb7550c44f9157585c6459d7460eda21_851x332.png)
## 3. postgresql数据库
### 3.1 添加postgresql驱动,修改pom.xml
(根据不同版本的数据库引入对应版本的驱动,下载地址:https://jdbc.postgresql.org/download.html)
```
org.postgresql
postgresql
42.2.6
```
### 3.2 修改数据库连接
```
增加spring下的配置
spring:
#postgresql 报错问题
jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
properties:
hibernate:
temp:
use_jdbc_metadata_defaults: false
修改druid配置
validationQuery: SELECT 1
url: jdbc:postgresql://localhost:5432/postgres
username: postgres
password: root
driver-class-name: org.postgresql.Driver
```
修改quartz配置
~~~
spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
~~~
## 4. JeecgBoot支持哪些数据库
| 数据库 | 支持 |
| --- | --- |
| MySQL | √ |
| Oracle11g | √ |
| Sqlserver2017 | √ |
| PostgreSQL | √ |
| DB2、Informix | √ |
| MariaDB | √ |
| SQLite、Hsqldb、Derby、H2 | √ |
| 达梦、人大金仓、神通 | √ |
| 华为高斯、虚谷、瀚高数据库 | √ |
| 阿里云PolarDB、PPAS、HerdDB | √ |
| Hive、HBase、CouchBase | √ |
';