coverity 1315775: proper getting of networkLabel

This commit is contained in:
Daan Hoogland 2015-08-12 01:10:31 +02:00
parent a3ae8e0645
commit 1ab3b96594

View File

@ -34,20 +34,15 @@ public abstract class Upgrade30xBase extends LegacyDbUpgrade {
protected String getNetworkLabelFromConfig(Connection conn, String name) {
String sql = "SELECT value FROM `cloud`.`configuration` where name = ?";
String networkLabel = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement(sql);
try (PreparedStatement pstmt = conn.prepareStatement(sql);) {
pstmt.setString(1,name);
rs = pstmt.executeQuery();
if (rs.next()) {
networkLabel = rs.getString(1);
try (ResultSet rs = pstmt.executeQuery();) {
if (rs.next()) {
networkLabel = rs.getString(1);
}
}
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to fetch network label from configuration", e);
} finally {
closeAutoCloseable(rs);
closeAutoCloseable(pstmt);
}
return networkLabel;
}