|
@@ -6,53 +6,89 @@ import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
import com.qmth.teachcloud.common.entity.SysConfig;
|
|
import com.qmth.teachcloud.common.entity.SysConfig;
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
import com.qmth.teachcloud.common.service.CommonCacheService;
|
|
import com.qmth.teachcloud.common.service.CommonCacheService;
|
|
|
|
+import com.qmth.teachcloud.common.bean.sync.TSyncDataStudent;
|
|
|
|
+import com.qmth.teachcloud.data.enums.DataType;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
|
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.sql.DataSource;
|
|
import javax.sql.DataSource;
|
|
-import java.sql.Connection;
|
|
|
|
-import java.sql.DriverManager;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Component
|
|
@Component
|
|
public class DataUtil {
|
|
public class DataUtil {
|
|
|
|
|
|
// 一页1000条
|
|
// 一页1000条
|
|
- private static int PAGE_SIZE = 1000;
|
|
|
|
|
|
+ private static int PAGE_SIZE = 2;
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private CommonCacheService commonCacheService;
|
|
private CommonCacheService commonCacheService;
|
|
|
|
|
|
- public List<OrgDataVo> listOrg(JdbcTemplate jdbcTemplate) {
|
|
|
|
- //sql语句
|
|
|
|
- String sql = "select * from sys_user";
|
|
|
|
|
|
+ public List<OrgDataVo> listOrg(JdbcTemplate jdbcTemplate, DataType dataType, String datasourceType) {
|
|
|
|
+
|
|
|
|
+ String sql;
|
|
|
|
+ if ("ORACLE".equals(datasourceType.trim())) {
|
|
|
|
+ sql = getOracleSql(dataType, false);
|
|
|
|
+ } else if ("MYSQL".equals(datasourceType.trim())) {
|
|
|
|
+ sql = getMysqlSql(dataType, false);
|
|
|
|
+ } else {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("只支持Oracle和Mysql数据库");
|
|
|
|
+ }
|
|
return query(jdbcTemplate, sql, OrgDataVo.class);
|
|
return query(jdbcTemplate, sql, OrgDataVo.class);
|
|
}
|
|
}
|
|
|
|
|
|
- public List<UserDataVo> listUser(JdbcTemplate jdbcTemplate) {
|
|
|
|
- //sql语句
|
|
|
|
- String sql = "select * from sys_user limit ? ?";
|
|
|
|
- return page(jdbcTemplate, sql, UserDataVo.class);
|
|
|
|
|
|
+ public List<UserDataVo> listUser(JdbcTemplate jdbcTemplate, DataType dataType, String datasourceType) {
|
|
|
|
+ String sql;
|
|
|
|
+ if ("ORACLE".equals(datasourceType.trim())) {
|
|
|
|
+ sql = getOracleSql(dataType, true, "code");
|
|
|
|
+ return pageOracle(jdbcTemplate, sql, UserDataVo.class);
|
|
|
|
+ } else if ("MYSQL".equals(datasourceType.trim())) {
|
|
|
|
+ sql = getMysqlSql(dataType, true);
|
|
|
|
+ return pageMysql(jdbcTemplate, sql, UserDataVo.class);
|
|
|
|
+ } else {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("只支持Oracle和Mysql数据库");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- public List<CourseDataVo> listCourse(JdbcTemplate jdbcTemplate) {
|
|
|
|
- //sql语句
|
|
|
|
- String sql = "select * from sys_user";
|
|
|
|
|
|
+ public List<CourseDataVo> listCourse(JdbcTemplate jdbcTemplate, DataType dataType, String datasourceType) {
|
|
|
|
+ String sql;
|
|
|
|
+ if ("ORACLE".equals(datasourceType.trim())) {
|
|
|
|
+ sql = getOracleSql(dataType, false);
|
|
|
|
+ } else if ("MYSQL".equals(datasourceType.trim())) {
|
|
|
|
+ sql = getMysqlSql(dataType, false);
|
|
|
|
+ } else {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("只支持Oracle和Mysql数据库");
|
|
|
|
+ }
|
|
return query(jdbcTemplate, sql, CourseDataVo.class);
|
|
return query(jdbcTemplate, sql, CourseDataVo.class);
|
|
}
|
|
}
|
|
|
|
|
|
- public List<ExamTaskDataVo> listExamTask(JdbcTemplate jdbcTemplate) {
|
|
|
|
- //sql语句
|
|
|
|
- String sql = "select * from sys_user";
|
|
|
|
|
|
+ public List<ExamTaskDataVo> listExamTask(JdbcTemplate jdbcTemplate, DataType dataType, String datasourceType) {
|
|
|
|
+ String sql;
|
|
|
|
+ if ("ORACLE".equals(datasourceType.trim())) {
|
|
|
|
+ sql = getOracleSql(dataType, false);
|
|
|
|
+ } else if ("MYSQL".equals(datasourceType.trim())) {
|
|
|
|
+ sql = getMysqlSql(dataType, false);
|
|
|
|
+ } else {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("只支持Oracle和Mysql数据库");
|
|
|
|
+ }
|
|
return query(jdbcTemplate, sql, ExamTaskDataVo.class);
|
|
return query(jdbcTemplate, sql, ExamTaskDataVo.class);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ public List<TSyncDataStudent> listExamStudent(JdbcTemplate jdbcTemplate, DataType dataType, String datasourceType) {
|
|
|
|
+ String sql;
|
|
|
|
+ if ("ORACLE".equals(datasourceType.trim())) {
|
|
|
|
+ sql = getOracleSql(dataType, true, "course_code", "student_code");
|
|
|
|
+ return pageOracle(jdbcTemplate, sql, TSyncDataStudent.class);
|
|
|
|
+ } else if ("MYSQL".equals(datasourceType.trim())) {
|
|
|
|
+ sql = getMysqlSql(dataType, true);
|
|
|
|
+ return pageMysql(jdbcTemplate, sql, TSyncDataStudent.class);
|
|
|
|
+ } else {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("只支持Oracle和Mysql数据库");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -61,12 +97,9 @@ public class DataUtil {
|
|
* @param sql
|
|
* @param sql
|
|
*/
|
|
*/
|
|
private <T> List<T> query(JdbcTemplate jdbcTemplate, String sql, Class<T> tClass) {
|
|
private <T> List<T> query(JdbcTemplate jdbcTemplate, String sql, Class<T> tClass) {
|
|
- if (sql.endsWith("limit ? ?")) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("sql中设置了分页参数");
|
|
|
|
- }
|
|
|
|
List<T> list;
|
|
List<T> list;
|
|
try {
|
|
try {
|
|
- list = jdbcTemplate.queryForList(sql, tClass);
|
|
|
|
|
|
+ list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(tClass));
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
throw ExceptionResultEnum.ERROR.exception("查询失败:" + e.getMessage());
|
|
throw ExceptionResultEnum.ERROR.exception("查询失败:" + e.getMessage());
|
|
}
|
|
}
|
|
@@ -78,10 +111,7 @@ public class DataUtil {
|
|
*
|
|
*
|
|
* @param sql
|
|
* @param sql
|
|
*/
|
|
*/
|
|
- private <T> List<T> page(JdbcTemplate jdbcTemplate, String sql, Class<T> tClass) {
|
|
|
|
- if (!sql.endsWith("limit ? ?")) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("sql中未设置分页参数");
|
|
|
|
- }
|
|
|
|
|
|
+ private <T> List<T> pageMysql(JdbcTemplate jdbcTemplate, String sql, Class<T> tClass) {
|
|
//将查询的语句封装到List集合中,集合中存储每一个员工实体
|
|
//将查询的语句封装到List集合中,集合中存储每一个员工实体
|
|
List<T> listAll = new ArrayList<>();
|
|
List<T> listAll = new ArrayList<>();
|
|
try {
|
|
try {
|
|
@@ -89,7 +119,7 @@ public class DataUtil {
|
|
int pageNumber = 0;
|
|
int pageNumber = 0;
|
|
do {
|
|
do {
|
|
int offset = pageNumber * PAGE_SIZE + PAGE_SIZE;
|
|
int offset = pageNumber * PAGE_SIZE + PAGE_SIZE;
|
|
- list = jdbcTemplate.queryForList(sql, tClass, pageNumber, offset);
|
|
|
|
|
|
+ list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(tClass), pageNumber, offset);
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
listAll.addAll(list);
|
|
listAll.addAll(list);
|
|
pageNumber++;
|
|
pageNumber++;
|
|
@@ -102,54 +132,63 @@ public class DataUtil {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 不分页
|
|
|
|
|
|
+ * 分页
|
|
*
|
|
*
|
|
* @param sql
|
|
* @param sql
|
|
*/
|
|
*/
|
|
- /*private <T> List<T> query(String sql, Class<T> tClass) {
|
|
|
|
- if (sql.endsWith("limit ? ?")) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("sql中设置了分页参数");
|
|
|
|
- }
|
|
|
|
- //创建QueryRunner
|
|
|
|
- QueryRunner qr = new QueryRunner(DruidJdbcUtils.getDataSource(createDataSourceMap()));
|
|
|
|
- List<T> list;
|
|
|
|
- try {
|
|
|
|
- list = qr.query(sql, new BeanListHandler<>(tClass));
|
|
|
|
- } catch (SQLException e) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("查询失败:" + e.getMessage());
|
|
|
|
- }
|
|
|
|
- return list;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 分页
|
|
|
|
- *//*
|
|
|
|
- private <T> List<T> page(String sql, Class<T> tClass) {
|
|
|
|
- if (!sql.endsWith("limit ? ?")) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("sql中未设置分页参数");
|
|
|
|
- }
|
|
|
|
- //创建QueryRunner
|
|
|
|
- QueryRunner qr = new QueryRunner(DruidJdbcUtils.getDataSource(createDataSourceMap()));
|
|
|
|
|
|
+ private <T> List<T> pageOracle(JdbcTemplate jdbcTemplate, String sql, Class<T> tClass) {
|
|
//将查询的语句封装到List集合中,集合中存储每一个员工实体
|
|
//将查询的语句封装到List集合中,集合中存储每一个员工实体
|
|
List<T> listAll = new ArrayList<>();
|
|
List<T> listAll = new ArrayList<>();
|
|
try {
|
|
try {
|
|
List<T> list;
|
|
List<T> list;
|
|
- int pageNumber = 0;
|
|
|
|
|
|
+ int pageNumber = 1;
|
|
do {
|
|
do {
|
|
- int offset = pageNumber * PAGE_SIZE + PAGE_SIZE;
|
|
|
|
- list = qr.query(sql, new BeanListHandler<>(tClass), pageNumber, offset);
|
|
|
|
|
|
+ int startIndex = PAGE_SIZE * (pageNumber - 1) + 1;
|
|
|
|
+ int endIndex = pageNumber * PAGE_SIZE;
|
|
|
|
+ list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(tClass), startIndex, endIndex);
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
listAll.addAll(list);
|
|
listAll.addAll(list);
|
|
pageNumber++;
|
|
pageNumber++;
|
|
}
|
|
}
|
|
} while (CollectionUtils.isNotEmpty(list));
|
|
} while (CollectionUtils.isNotEmpty(list));
|
|
- } catch (SQLException e) {
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
throw ExceptionResultEnum.ERROR.exception("查询失败:" + e.getMessage());
|
|
throw ExceptionResultEnum.ERROR.exception("查询失败:" + e.getMessage());
|
|
}
|
|
}
|
|
return listAll;
|
|
return listAll;
|
|
- }*/
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String getMysqlSql(DataType dataType, boolean isPage) {
|
|
|
|
+ //sql语句
|
|
|
|
+ String sql;
|
|
|
|
+ if (isPage) {
|
|
|
|
+ sql = "select * from " + dataType.getTable() + " limit ? ?";
|
|
|
|
+ } else {
|
|
|
|
+ sql = "select * from " + dataType.getTable();
|
|
|
|
+ }
|
|
|
|
+ return sql;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String getOracleSql(DataType dataType, boolean isPage, String... sortColumn) {
|
|
|
|
+ //sql语句
|
|
|
|
+ String sql;
|
|
|
|
+ if (isPage) {
|
|
|
|
+ StringJoiner stringJoiner = new StringJoiner("");
|
|
|
|
+ stringJoiner.add("SELECT * FROM (SELECT t.*, ROW_NUMBER() OVER (ORDER BY ");
|
|
|
|
+ StringJoiner sortStr = new StringJoiner(",");
|
|
|
|
+ for (String s : sortColumn) {
|
|
|
|
+ sortStr.add("\"" + s + "\"");
|
|
|
|
+ }
|
|
|
|
+ stringJoiner.add(sortStr.toString());
|
|
|
|
+ stringJoiner.add(") AS rn FROM ");
|
|
|
|
+ stringJoiner.add("\"" + dataType.getTable() + "\"");
|
|
|
|
+ stringJoiner.add(" t) WHERE rn BETWEEN ? AND ?");
|
|
|
|
+ sql = stringJoiner.toString();
|
|
|
|
+ } else {
|
|
|
|
+ sql = "select * from \"" + dataType.getTable() + "\"";
|
|
|
|
+ }
|
|
|
|
+ return sql;
|
|
|
|
+ }
|
|
|
|
+
|
|
public DataSource createDataSourceMap(Long schoolId) {
|
|
public DataSource createDataSourceMap(Long schoolId) {
|
|
SysConfig datasourceType = commonCacheService.addSysConfigCache(schoolId, SystemConstant.DATA_DATASOURCE_TYPE);
|
|
SysConfig datasourceType = commonCacheService.addSysConfigCache(schoolId, SystemConstant.DATA_DATASOURCE_TYPE);
|
|
if (datasourceType == null || StringUtils.isBlank(datasourceType.getConfigValue())) {
|
|
if (datasourceType == null || StringUtils.isBlank(datasourceType.getConfigValue())) {
|
|
@@ -205,37 +244,37 @@ public class DataUtil {
|
|
|
|
|
|
|
|
|
|
public DataSource createDataSourceMap(List<SysConfigResult> params) {
|
|
public DataSource createDataSourceMap(List<SysConfigResult> params) {
|
|
- SysConfigResult datasourceType = params.stream().filter(m->m.getCode().equals(SystemConstant.DATA_DATASOURCE_TYPE)).findFirst().orElse(null);
|
|
|
|
|
|
+ SysConfigResult datasourceType = params.stream().filter(m -> m.getCode().equals(SystemConstant.DATA_DATASOURCE_TYPE)).findFirst().orElse(null);
|
|
if (datasourceType == null || StringUtils.isBlank(datasourceType.getValue().toString())) {
|
|
if (datasourceType == null || StringUtils.isBlank(datasourceType.getValue().toString())) {
|
|
throw ExceptionResultEnum.ERROR.exception("未设置数据库类型");
|
|
throw ExceptionResultEnum.ERROR.exception("未设置数据库类型");
|
|
}
|
|
}
|
|
String type = datasourceType.getValue().toString().trim();
|
|
String type = datasourceType.getValue().toString().trim();
|
|
// 数据库HOST
|
|
// 数据库HOST
|
|
- SysConfigResult datasourceHost = params.stream().filter(m->m.getCode().equals(SystemConstant.DATA_DATASOURCE_HOST)).findFirst().orElse(null);
|
|
|
|
|
|
+ SysConfigResult datasourceHost = params.stream().filter(m -> m.getCode().equals(SystemConstant.DATA_DATASOURCE_HOST)).findFirst().orElse(null);
|
|
if (datasourceHost == null || StringUtils.isBlank(datasourceHost.getValue().toString())) {
|
|
if (datasourceHost == null || StringUtils.isBlank(datasourceHost.getValue().toString())) {
|
|
throw ExceptionResultEnum.ERROR.exception("未设置HOST");
|
|
throw ExceptionResultEnum.ERROR.exception("未设置HOST");
|
|
}
|
|
}
|
|
String host = datasourceHost.getValue().toString().trim();
|
|
String host = datasourceHost.getValue().toString().trim();
|
|
// 数据库PORT
|
|
// 数据库PORT
|
|
- SysConfigResult datasourcePort = params.stream().filter(m->m.getCode().equals(SystemConstant.DATA_DATASOURCE_PORT)).findFirst().orElse(null);
|
|
|
|
|
|
+ SysConfigResult datasourcePort = params.stream().filter(m -> m.getCode().equals(SystemConstant.DATA_DATASOURCE_PORT)).findFirst().orElse(null);
|
|
if (datasourcePort == null || StringUtils.isBlank(datasourcePort.getValue().toString())) {
|
|
if (datasourcePort == null || StringUtils.isBlank(datasourcePort.getValue().toString())) {
|
|
throw ExceptionResultEnum.ERROR.exception("未设置端口");
|
|
throw ExceptionResultEnum.ERROR.exception("未设置端口");
|
|
}
|
|
}
|
|
String port = datasourcePort.getValue().toString().trim();
|
|
String port = datasourcePort.getValue().toString().trim();
|
|
// 数据库DataName
|
|
// 数据库DataName
|
|
- SysConfigResult datasourceDataName = params.stream().filter(m->m.getCode().equals(SystemConstant.DATA_DATASOURCE_DATANAME)).findFirst().orElse(null);
|
|
|
|
|
|
+ SysConfigResult datasourceDataName = params.stream().filter(m -> m.getCode().equals(SystemConstant.DATA_DATASOURCE_DATANAME)).findFirst().orElse(null);
|
|
if (datasourceDataName == null || StringUtils.isBlank(datasourceDataName.getValue().toString())) {
|
|
if (datasourceDataName == null || StringUtils.isBlank(datasourceDataName.getValue().toString())) {
|
|
throw ExceptionResultEnum.ERROR.exception("未设置数据库名");
|
|
throw ExceptionResultEnum.ERROR.exception("未设置数据库名");
|
|
}
|
|
}
|
|
String dataName = datasourceDataName.getValue().toString().trim();
|
|
String dataName = datasourceDataName.getValue().toString().trim();
|
|
// 数据库用户名
|
|
// 数据库用户名
|
|
- SysConfigResult datasourceUserName = params.stream().filter(m->m.getCode().equals(SystemConstant.DATA_DATASOURCE_USERNAME)).findFirst().orElse(null);
|
|
|
|
|
|
+ SysConfigResult datasourceUserName = params.stream().filter(m -> m.getCode().equals(SystemConstant.DATA_DATASOURCE_USERNAME)).findFirst().orElse(null);
|
|
if (datasourceUserName == null || StringUtils.isBlank(datasourceUserName.getValue().toString())) {
|
|
if (datasourceUserName == null || StringUtils.isBlank(datasourceUserName.getValue().toString())) {
|
|
throw ExceptionResultEnum.ERROR.exception("未设置用户名");
|
|
throw ExceptionResultEnum.ERROR.exception("未设置用户名");
|
|
}
|
|
}
|
|
String userName = datasourceUserName.getValue().toString().trim();
|
|
String userName = datasourceUserName.getValue().toString().trim();
|
|
// 数据库密码
|
|
// 数据库密码
|
|
- SysConfigResult datasourcePassword = params.stream().filter(m->m.getCode().equals(SystemConstant.DATA_DATASOURCE_PASSWORD)).findFirst().orElse(null);
|
|
|
|
|
|
+ SysConfigResult datasourcePassword = params.stream().filter(m -> m.getCode().equals(SystemConstant.DATA_DATASOURCE_PASSWORD)).findFirst().orElse(null);
|
|
if (datasourcePassword == null || StringUtils.isBlank(datasourcePassword.getValue().toString())) {
|
|
if (datasourcePassword == null || StringUtils.isBlank(datasourcePassword.getValue().toString())) {
|
|
throw ExceptionResultEnum.ERROR.exception("未设置密码");
|
|
throw ExceptionResultEnum.ERROR.exception("未设置密码");
|
|
}
|
|
}
|
|
@@ -245,7 +284,7 @@ public class DataUtil {
|
|
String driverClassName;
|
|
String driverClassName;
|
|
String url;
|
|
String url;
|
|
if ("ORACLE".equals(type)) {
|
|
if ("ORACLE".equals(type)) {
|
|
- driverClassName = "com.mysql.jdbc.Driver";
|
|
|
|
|
|
+ driverClassName = "oracle.jdbc.driver.OracleDriver";
|
|
url = "jdbc:oracle:thin:@" + host + ":" + port + ":" + dataName;
|
|
url = "jdbc:oracle:thin:@" + host + ":" + port + ":" + dataName;
|
|
} else if ("MYSQL".equals(type)) {
|
|
} else if ("MYSQL".equals(type)) {
|
|
driverClassName = "com.mysql.jdbc.Driver";
|
|
driverClassName = "com.mysql.jdbc.Driver";
|
|
@@ -261,38 +300,4 @@ public class DataUtil {
|
|
return new DriverManagerDataSource(url, userName, password);
|
|
return new DriverManagerDataSource(url, userName, password);
|
|
}
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
|
- sqlConn("0", "localhost", "3306", "teachcloud-3.4.3", "root", "12345678");
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public static String sqlConn(String databaseType, String address, String port, String databaseName, String userName, String password) {
|
|
|
|
- String driverName = null;
|
|
|
|
- String url = null;
|
|
|
|
- if ("0".equals(databaseType)) {
|
|
|
|
- //mysql
|
|
|
|
- driverName = "com.mysql.cj.jdbc.Driver";
|
|
|
|
- url = "jdbc:mysql://" + address + ":" + port + "/" + databaseName + "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
|
|
|
|
- } else if ("1".equals(databaseType)) {
|
|
|
|
- //oracle
|
|
|
|
- driverName = "oracle.jdbc.driver.OracleDriver";
|
|
|
|
- url = "jdbc:oracle:thin:@" + address + ":" + port + ":" + databaseName;
|
|
|
|
- } else if ("2".equals(databaseType)) {
|
|
|
|
- //sqlserver
|
|
|
|
- driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
|
|
|
|
- url = "jdbc:sqlserver://" + address + ":" + port + ";DatabaseName=" + databaseName;
|
|
|
|
- }
|
|
|
|
- try {
|
|
|
|
- Class.forName(driverName);
|
|
|
|
- Connection connection = DriverManager.getConnection(url, userName, password);
|
|
|
|
- connection.close();
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- return "测试失败";
|
|
|
|
- }
|
|
|
|
- return "测试成功";
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public List<ExamStudentDataVo> listExamStudent(JdbcTemplate jdbcTemplate) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|