diff --git a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java index af90caee8..51a90918b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java +++ b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java @@ -509,13 +509,13 @@ public class SQLExec extends JDBCTask { return; } + ResultSet resultSet = null; try { totalSql++; log("SQL: " + sql, Project.MSG_VERBOSE); boolean ret; int updateCount = 0, updateCountTotal = 0; - ResultSet resultSet = null; ret = statement.execute(sql); updateCount = statement.getUpdateCount(); @@ -559,6 +559,28 @@ public class SQLExec extends JDBCTask { throw e; } log(e.toString(), Project.MSG_ERR); + } finally { + if (resultSet != null) { + resultSet.close(); + } + } + } + + /** + * print any results in the statement + * @deprecated use {@link #printResults(java.sql.ResultSet, java.io.PrintStream) the two arg version} instead. + * @param out the place to print results + * @throws SQLException on SQL problems. + */ + protected void printResults(PrintStream out) throws SQLException { + ResultSet rs = null; + rs = statement.getResultSet(); + try { + printResults(rs, out); + } finally { + if (rs != null) { + rs.close(); + } } } @@ -567,6 +589,7 @@ public class SQLExec extends JDBCTask { * @param rs the resultset to print information about * @param out the place to print results * @throws SQLException on SQL problems. + * @since Ant 1.7 */ protected void printResults(ResultSet rs, PrintStream out) throws SQLException { if (rs != null) {