校验对象增加默认常用选择项
This commit is contained in:
@@ -22,14 +22,17 @@ public class MySQLExecutor {
|
||||
* @param user 数据库用户名
|
||||
* @param password 数据库密码
|
||||
* @param columnNameList 所有列名集合
|
||||
* @param sqlSpecialResultMap 存储sql特有的响应信息字段结果值
|
||||
* @return 查询结果(每行数据为一个 Map)
|
||||
*/
|
||||
public static List<Map<String, Object>> executeQuery(String sql, String url, String user, String password, List<String> columnNameList) {
|
||||
public static List<Map<String, Object>> executeQuery(String sql, String url, String user, String password, List<String> columnNameList, Map<String, String> sqlSpecialResultMap) {
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
try (Connection connection = DriverManager.getConnection(url, user, password);
|
||||
Statement statement = connection.createStatement()) {
|
||||
// 执行查询,限制最大100行
|
||||
try (ResultSet resultSet = statement.executeQuery(sql.replaceAll(";", "") + " LIMIT 100")) {
|
||||
boolean isResultSet = statement.execute(sql.replaceAll(";", ""));
|
||||
if (isResultSet) {
|
||||
// 处理查询结果
|
||||
ResultSet resultSet = statement.getResultSet();
|
||||
// 获取结果集的元数据
|
||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||
int columnCount = metaData.getColumnCount();
|
||||
@@ -52,6 +55,10 @@ public class MySQLExecutor {
|
||||
}
|
||||
result.add(row);
|
||||
}
|
||||
} else {
|
||||
// 处理非查询语句
|
||||
int rowsAffected = statement.getUpdateCount();
|
||||
sqlSpecialResultMap.put("${AFFECT_ROWS}", String.valueOf(rowsAffected));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
Reference in New Issue
Block a user