Skip to content

Commit df04c4a

Browse files
[fix-9991][worker]fix statement is closed before resultSet.getMetaData() (#10014)
1 parent baf654c commit df04c4a

1 file changed

Lines changed: 6 additions & 16 deletions

File tree

  • dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql

dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ public void executeFuncAndSql(List<SqlBinds> mainStatementsBinds,
179179
List<SqlBinds> postStatementsBinds,
180180
List<String> createFuncs) throws Exception {
181181
Connection connection = null;
182-
ResultSet resultSet = null;
183182
try {
184183

185184
// create connection
@@ -197,8 +196,7 @@ public void executeFuncAndSql(List<SqlBinds> mainStatementsBinds,
197196
// decide whether to executeQuery or executeUpdate based on sqlType
198197
if (sqlParameters.getSqlType() == SqlType.QUERY.ordinal()) {
199198
// query statements need to be convert to JsonArray and inserted into Alert to send
200-
resultSet = executeQuery(connection, mainStatementsBinds.get(0), "main");
201-
result = resultProcess(resultSet);
199+
result = executeQuery(connection, mainStatementsBinds.get(0), "main");
202200
} else if (sqlParameters.getSqlType() == SqlType.NON_QUERY.ordinal()) {
203201
// non query statement
204202
String updateResult = executeUpdate(connection, mainStatementsBinds, "main");
@@ -213,7 +211,7 @@ public void executeFuncAndSql(List<SqlBinds> mainStatementsBinds,
213211
logger.error("execute sql error: {}", e.getMessage());
214212
throw e;
215213
} finally {
216-
close(resultSet, connection);
214+
close(connection);
217215
}
218216
}
219217

@@ -292,10 +290,11 @@ private void sendAttachment(int groupId, String title, String content) {
292290
setTaskAlertInfo(taskAlertInfo);
293291
}
294292

295-
private ResultSet executeQuery(Connection connection, SqlBinds sqlBinds, String handlerType) throws Exception {
293+
private String executeQuery(Connection connection, SqlBinds sqlBinds, String handlerType) throws Exception {
296294
try (PreparedStatement statement = prepareStatementAndBind(connection, sqlBinds)) {
297295
logger.info("{} statement execute query, for sql: {}", handlerType, sqlBinds.getSql());
298-
return statement.executeQuery();
296+
ResultSet resultSet = statement.executeQuery();
297+
return resultProcess(resultSet);
299298
}
300299
}
301300

@@ -329,18 +328,9 @@ private void createTempFunction(Connection connection,
329328
/**
330329
* close jdbc resource
331330
*
332-
* @param resultSet resultSet
333331
* @param connection connection
334332
*/
335-
private void close(ResultSet resultSet, Connection connection) {
336-
if (resultSet != null) {
337-
try {
338-
resultSet.close();
339-
} catch (SQLException e) {
340-
logger.error("close result set error : {}", e.getMessage(), e);
341-
}
342-
}
343-
333+
private void close(Connection connection) {
344334
if (connection != null) {
345335
try {
346336
connection.close();

0 commit comments

Comments
 (0)