修改
This commit is contained in:
@@ -25,6 +25,7 @@ public class MysqlUtils {
|
||||
private static final String filePath = "/ogsapp/resultList/";
|
||||
|
||||
private static String EXEC_CODE = "0";
|
||||
private static String EXEC_FILE = "";
|
||||
|
||||
// 需要排除的系统数据库
|
||||
private static final List<String> SYSTEM_DATABASES = Arrays.asList(
|
||||
@@ -213,12 +214,13 @@ public class MysqlUtils {
|
||||
|
||||
|
||||
public static ExecResult getExecResult(BizDbConfig dbConfig, String sql) {
|
||||
String fileName = filePath + vId.getCid() + "_data.xlsx";
|
||||
|
||||
try {
|
||||
Connection conn = getConnection(dbConfig.getDbIp(), dbConfig.getDbPort(), dbConfig.getDbUsername(), dbConfig.getDbPassword());
|
||||
Statement statement = conn.createStatement();
|
||||
boolean isQuery = sql.trim().toUpperCase().startsWith("SELECT");
|
||||
if (isQuery) {
|
||||
EXEC_FILE = filePath + vId.getCid() + "_data.xlsx";
|
||||
ResultSet rs = statement.executeQuery(sql);
|
||||
List<Map<String, Object>> resultList = new ArrayList<>();
|
||||
ResultSetMetaData metaData = rs.getMetaData();
|
||||
@@ -233,19 +235,20 @@ public class MysqlUtils {
|
||||
resultList.add(rowMap);
|
||||
}
|
||||
List<Map<String, Object>> mapList = CollUtil.newArrayList(resultList);
|
||||
BigExcelWriter writer = ExcelUtil.getBigWriter(fileName);
|
||||
BigExcelWriter writer = ExcelUtil.getBigWriter(EXEC_FILE);
|
||||
writer.write(mapList);
|
||||
writer.close();
|
||||
logger.info(sql, "执行成功,影响行数:", resultList.size(), "执行结果:", fileName);
|
||||
EXEC_CODE = "1";
|
||||
logger.info(sql, "执行成功,影响行数:", resultList.size(), "执行结果:", EXEC_FILE);
|
||||
} else {
|
||||
int affectedRows = statement.executeUpdate(sql);
|
||||
EXEC_CODE = "1";
|
||||
logger.info(sql, "执行成功,影响行数:", affectedRows);
|
||||
}
|
||||
EXEC_CODE = "1";
|
||||
} catch (Exception e) {
|
||||
EXEC_CODE = "0";
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
return new ExecResult(EXEC_CODE, fileName);
|
||||
return new ExecResult(EXEC_CODE, EXEC_FILE);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user