diff --git a/framework/db/src/com/cloud/utils/db/ConnectionConcierge.java b/framework/db/src/com/cloud/utils/db/ConnectionConcierge.java index f5a3b2f0f17..a1c473d5ffd 100644 --- a/framework/db/src/com/cloud/utils/db/ConnectionConcierge.java +++ b/framework/db/src/com/cloud/utils/db/ConnectionConcierge.java @@ -142,26 +142,17 @@ public class ConnectionConcierge { } protected String testValidity(String name, Connection conn) { - PreparedStatement pstmt = null; - try { - if (conn != null) { - synchronized (conn) { - pstmt = conn.prepareStatement("SELECT 1"); + if (conn != null) { + synchronized (conn) { + try (PreparedStatement pstmt = conn.prepareStatement("SELECT 1");) { pstmt.executeQuery(); - } - } - return null; - } catch (Throwable th) { - s_logger.error("Unable to keep the db connection for " + name, th); - return th.toString(); - } finally { - if (pstmt != null) { - try { - pstmt.close(); - } catch (SQLException e) { + } catch (Throwable th) { + s_logger.error("Unable to keep the db connection for " + name, th); + return th.toString(); } } } + return null; } @Override