Fix for missing handle in batching case.
@@ -2590,6 +2590,13 @@ public class SQLServerPreparedStatement extends SQLServerStatement implements IS
}
}
+ // Retry execution if existing handle could not be re-used.
+ int attempt = 0;
+ while (true) {
+
+ ++attempt;
+ try {
+
// Re-use handle if available, requires parameter definitions which are not available until here.
if (reuseCachedHandle(hasNewTypeDefinitions, false)) {
hasNewTypeDefinitions = false;
@@ -2612,7 +2619,9 @@ public class SQLServerPreparedStatement extends SQLServerStatement implements IS
// But we may also need to reprepare the statement if, for example,
// the size of a batch's string parameter values changes such
// that repreparation is necessary.
+ if(1 == attempt)
++numBatchesPrepared;
+
if (doPrepExec(tdsWriter, batchParam, hasNewTypeDefinitions, hasExistingTypeDefinitions) || numBatchesPrepared == numBatches) {
ensureExecuteResultsReader(batchCommand.startResponse(getIsResponseBufferingAdaptive()));
@@ -2654,7 +2663,9 @@ public class SQLServerPreparedStatement extends SQLServerStatement implements IS
// In batch execution, we have a special update count
// to indicate that no information was returned
- batchCommand.updateCounts[numBatchesExecuted++] = (-1 == updateCount) ? Statement.SUCCESS_NO_INFO : updateCount;
+ batchCommand.updateCounts[numBatchesExecuted] = (-1 == updateCount) ? Statement.SUCCESS_NO_INFO : updateCount;
+ if(1 == attempt)
+ numBatchesExecuted++;
processBatch();
}
@@ -2664,6 +2675,15 @@ public class SQLServerPreparedStatement extends SQLServerStatement implements IS
assert numBatchesExecuted == numBatchesPrepared;
}
}
+ catch(SQLException e) {
+ if (retryBasedOnFailedReuseOfCachedHandle(e, attempt))
+ continue;
+ else
+ throw e;
+ }
+ break;
+ }
+ }
}
public final void setCharacterStream(int parameterIndex,
