2.2.2 JDBC數(shù)據源
如果你(nǐ)希望将URule Pro的規則存儲在指定的數(shù)據源中,你(nǐ)可(kě)以使用JDBC數(shù)據源:
JDBC數(shù)據源利用DBCP配置數(shù)據源,配置界面如下:
支持多(duō)種類型的數(shù)據源,例如:
- DB2
- 達夢數(shù)據庫
- HSQL
- MYSQL
- ORACLE
- PostgreSQL
- SqlServer
根據不通(tōng)的數(shù)據源類型設置不通(tōng)的驅動類,連接URL以及用戶名密碼。
如果使用JDBC數(shù)據源,需要确保當前項目下有(yǒu)對應的JDBC驅動包存在
相關POM的配置參考:
<!-- MYSQL數(shù)據庫 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<!-- SQLServer數(shù)據庫 -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>8.4.1.jre8</version>
</dependency>
<!-- Informix數(shù)據庫 -->
<dependency>
<groupId>com.ibm.informix</groupId>
<artifactId>jdbc</artifactId>
<version>4.50.4.1</version>
</dependency>
<!-- Oracle數(shù)據庫 -->
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>
<!-- 達夢數(shù)據庫 -->
<dependency>
<groupId>dm</groupId>
<artifactId>dm-connector-java</artifactId>
<version>8.1.1.126</version>
</dependency>
<!-- PostgreSQL數(shù)據庫 -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.2</version>
</dependency>
<!-- DB2數(shù)據庫 -->
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc4</artifactId>
<version>10.1</version>
</dependency>
關于驗證鏈接SQL
驗證鏈接SQL對于不通(tōng)的數(shù)據庫是有(yǒu)差别的,如果配錯數(shù)據鏈接驗證就無法通(tōng)過,這兒列出一些(xiē)常用數(shù)據庫的驗證SQL:
數(shù)據庫 | 驗證SQL |
---|---|
HSQL | select 1 from INFORMATION_SCHEMA.SYSTEM_USERS |
Oracle | select 1 from dual |
IBM DB2 | select 1 from sysibm.sysdummy1 |
MySQL | select 1 |
Microsoft SQLServer | select 1 |
SQLite | select 1 |
DM | SELECT 1; |
PostgreSQL | select version(); |
Informix | select 1 |
Spring定義數(shù)據源
如果采用Spring配置文件定義數(shù)據源,參考配置:
urule.store.database.driver=com.mysql.jdbc.Driver
urule.store.database.password=password
urule.config.type=jdbc
urule.store.database.validationQuery=select 1
urule.store.database.maxIdle=10
urule.store.database.initialsize=0
urule.store.database.platform=mysql
urule.store.database.maxTotal=10
urule.store.database.username=root
urule.store.database.url=jdbc:mysql://localhost:3306/urule?useUnicode=true&characterEncoding=UTF-8
urule.store.database.minIdle=0