Source:
<code>public int[] executeBatch() throws SQLException { checkClosed(); try { warningChain = null; if (batchParameterValues == null || batchParameterValues.isEmpty()) { return new int[0]; } int[] counts = new int[batchParameterValues.size()]; Arrays.fill(counts, SUCCESS_NO_INFO); List<Object[]> generatedKeys = new ArrayList<>(); BindExecCommand command = connection.getProtocol().createBindExec(null, null, parameterTypes, Collections.emptyList(), resultFields, Object[].class); List<Type> lastParameterTypes = null; List<ResultField> lastResultFields = null; for (int c = 0, sz = batchParameterValues.size(); c < sz; ++c) { List<Type> parameterTypes = mergeTypes(batchParameterTypes.get(c), lastParameterTypes); if (lastParameterTypes == null || !lastParameterTypes.equals(parameterTypes)) { PrepareCommand prep = connection.getProtocol().createPrepare(null, sqlText, parameterTypes); connection.execute(prep, true); parameterTypes = prep.getDescribedParameterTypes(); lastParameterTypes = parameterTypes; lastResultFields = prep.getDescribedResultFields(); } List<Object> parameterValues = batchParameterValues.get(c); command.setParameterTypes(parameterTypes); command.setParameterValues(parameterValues); SQLWarning warnings = connection.execute(command, true); warningChain = chainWarnings(warningChain, warnings); List<QueryCommand.ResultBatch> resultBatches = command.getResultBatches(); if (resultBatches.size() != 1) { throw new BatchUpdateException(counts); } QueryCommand.ResultBatch resultBatch = resultBatches.get(0); if (resultBatch.rowsAffected == null) { counts[c] = 0; } else { counts[c] = (int) (long) resultBatch.rowsAffected; } if (wantsGeneratedKeys) { generatedKeys.add((Object[]) resultBatch.results.get(0)); } } if (generatedKeysResultSet != null && !generatedKeysResultSet.isClosed()) { generatedKeysResultSet.internalClose(); } <START> <END> generatedKeysResultSet = createResultSet(lastResultFields, generatedKeys); return counts; } finally { batchParameterTypes = null; batchParameterValues = null; } }</code><technical_language>This code removed. executeBatch is missing a call closeResultSets, close activeResultSets, outset of method; executeXXX methods required do. generatedKeysResultSet is in activeResultSets list</technical_language>

Target:
public int[] executeBatch() throws SQLException { checkClosed(); closeResultSets(); try { warningChain = null; if (batchParameterValues == null || batchParameterValues.isEmpty()) { return new int[0]; } int[] counts = new int[batchParameterValues.size()]; Arrays.fill(counts, SUCCESS_NO_INFO); List<Object[]> generatedKeys = new ArrayList<>(); BindExecCommand command = connection.getProtocol().createBindExec(null, null, parameterTypes, Collections.emptyList(), resultFields, Object[].class); List<Type> lastParameterTypes = null; List<ResultField> lastResultFields = null; for (int c = 0, sz = batchParameterValues.size(); c < sz; ++c) { List<Type> parameterTypes = mergeTypes(batchParameterTypes.get(c), lastParameterTypes); if (lastParameterTypes == null || !lastParameterTypes.equals(parameterTypes)) { PrepareCommand prep = connection.getProtocol().createPrepare(null, sqlText, parameterTypes); connection.execute(prep, true); parameterTypes = prep.getDescribedParameterTypes(); lastParameterTypes = parameterTypes; lastResultFields = prep.getDescribedResultFields(); } List<Object> parameterValues = batchParameterValues.get(c); command.setParameterTypes(parameterTypes); command.setParameterValues(parameterValues); SQLWarning warnings = connection.execute(command, true); warningChain = chainWarnings(warningChain, warnings); List<QueryCommand.ResultBatch> resultBatches = command.getResultBatches(); if (resultBatches.size() != 1) { throw new BatchUpdateException(counts); } QueryCommand.ResultBatch resultBatch = resultBatches.get(0); if (resultBatch.rowsAffected == null) { counts[c] = 0; } else { counts[c] = (int) (long) resultBatch.rowsAffected; } if (wantsGeneratedKeys) { generatedKeys.add((Object[]) resultBatch.results.get(0)); } } generatedKeysResultSet = createResultSet(lastResultFields, generatedKeys); return counts; } finally { batchParameterTypes = null; batchParameterValues = null; } }