Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix | Fix possible Statement Leak in SQLServerConnection.isValid() API #955

Merged
merged 15 commits into from
Mar 11, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -5568,9 +5568,8 @@ public boolean isValid(int timeout) throws SQLException {
if (isSessionUnAvailable())
return false;

try {
SQLServerStatement stmt = new SQLServerStatement(this, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY, SQLServerStatementColumnEncryptionSetting.UseConnectionSetting);
try (SQLServerStatement stmt = new SQLServerStatement(this, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY, SQLServerStatementColumnEncryptionSetting.UseConnectionSetting)) {

// If asked, limit the time to wait for the query to complete.
if (0 != timeout)
Expand All @@ -5581,13 +5580,13 @@ public boolean isValid(int timeout) throws SQLException {
// If a timeout was provided, execution throws an "query timed out" exception
// if the query fails to execute in that time.
stmt.executeQueryInternal("SELECT 1");
stmt.close();
isValid = true;
} catch (SQLException e) {
// Do not propagate SQLExceptions from query execution or statement closure.
// The connection is considered to be invalid if the statement fails to close,
// even though query execution succeeded.
connectionlogger.fine(toString() + " Exception checking connection validity: " + e.getMessage());
isValid = false;
cheenamalhotra marked this conversation as resolved.
Show resolved Hide resolved
}

loggerExternal.exiting(getClassNameLogging(), "isValid", isValid);
Expand Down