diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 1571f5bec..18a27cc95 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -7598,7 +7598,7 @@ public T unwrap(Class iface) throws SQLException { } /** request started flag */ - private boolean requestStarted = false; + private volatile boolean requestStarted = false; /** original database autocommit mode */ private boolean originalDatabaseAutoCommitMode; @@ -7740,9 +7740,13 @@ void endRequestInternal() throws SQLException { sqlWarnings = originalSqlWarnings; if (null != openStatements) { while (!openStatements.isEmpty()) { - try (Statement st = openStatements.get(0)) {} + Statement st = openStatements.get(0); + try { + st.close(); + } finally { + removeOpenStatement((SQLServerStatement) st); + } } - openStatements.clear(); } requestStarted = false; } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java index fef51bc6a..ab9e9fbe2 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java @@ -541,7 +541,7 @@ boolean onDone(TDSReader tdsReader) throws SQLServerException { /** * True is the statement is closed */ - boolean bIsClosed; + volatile boolean bIsClosed; /** * True if the user requested to driver to generate insert keys