This commit is contained in:
2023-06-20 17:20:28 +08:00
parent efab939bdf
commit 2ec376f0f8
10 changed files with 292 additions and 255 deletions

View File

@ -23,32 +23,37 @@ public enum DataBaseEnum {
*/
MY_SQL("MySQL",
"jdbc:mysql://{}:{}/{}?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowMultiQueries=true",
"com.mysql.cj.jdbc.Driver"),
"com.mysql.cj.jdbc.Driver",
"SELECT 1"),
/**
* Oracle
*/
ORACLE("Oracle",
"jdbc:oracle:thin:@//localhost:1521/{}",
"oracle.jdbc.OracleDriver"),
"jdbc:oracle:thin:@//{}:{}/{}",
"oracle.jdbc.OracleDriver",
"SELECT 1 from DUAL"),
/**
* PostgreSQL
*/
POSTGRE_SQL("PostgreSQL",
"jdbc:postgresql://{}:{}/mydb?currentSchema={}&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowMultiQueries=true",
"org.postgresql.Driver"),
"org.postgresql.Driver",
"SELECT 1"),
/**
* SQL Server
*/
SQL_SERVER("Microsoft SQL Server",
"jdbc:sqlserver://localhost:1433;DatabaseName={};SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true",
"com.microsoft.sqlserver.jdbc.SQLServerDriver");
"com.microsoft.sqlserver.jdbc.SQLServerDriver",
"SELECT 1");
private final String type;
private final String url;
private final String driver;
private final String checkSql;
public static String getDriver(String type) {
@ -68,4 +73,13 @@ public enum DataBaseEnum {
}
throw new ServiceException(StrUtil.format("未找到数据库Url, Type: {}", type));
}
public static String getCheckSql(String type) {
for (DataBaseEnum dataBaseEnum : values()) {
if (dataBaseEnum.getType().equals(type)) {
return dataBaseEnum.checkSql;
}
}
throw new ServiceException(StrUtil.format("未找到数据库checkSql, Type: {}", type));
}
}