diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade218to22Premium.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade218to22Premium.java index edf453c96ec..10ae5b0b33b 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade218to22Premium.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade218to22Premium.java @@ -57,42 +57,40 @@ public class Upgrade218to22Premium extends Upgrade218to22 { } private void updateUserStats(Connection conn) { - try { - - // update device_id information - PreparedStatement pstmt = - conn.prepareStatement("update cloud_usage.user_statistics uus set device_id = " + "(select device_id from cloud.user_statistics us where uus.id = us.id)"); + try ( // update device_id information + PreparedStatement pstmt = conn.prepareStatement( + "update cloud_usage.user_statistics uus set device_id = (select device_id from cloud.user_statistics us where uus.id = us.id)" + ); + ) { pstmt.executeUpdate(); - pstmt.close(); s_logger.debug("Upgraded cloud_usage user_statistics with deviceId"); - - // update host_id information in usage_network - PreparedStatement pstmt1 = - conn.prepareStatement("update cloud_usage.usage_network un set host_id = " - + "(select device_id from cloud_usage.user_statistics us where us.account_id = un.account_id and us.data_center_id = un.zone_id)"); - pstmt1.executeUpdate(); - pstmt1.close(); - - s_logger.debug("Upgraded cloud_usage usage_network with hostId"); - } catch (Exception e) { throw new CloudRuntimeException("Failed to upgrade user stats: ", e); } + + try ( // update host_id information in usage_network + PreparedStatement pstmt1 = conn.prepareStatement( + "update cloud_usage.usage_network un set host_id = " + + "(select device_id from cloud_usage.user_statistics us where us.account_id = un.account_id and us.data_center_id = un.zone_id)"); + ) { + pstmt1.executeUpdate(); + + s_logger.debug("Upgraded cloud_usage usage_network with hostId"); + } catch (Exception e) { + throw new CloudRuntimeException("Failed to upgrade network usage stats: ", e); + } } private void updateUsageIpAddress(Connection conn) { - try { - - // update id information + try ( // update id information PreparedStatement pstmt = conn.prepareStatement("update cloud_usage.usage_ip_address uip set id = " + "(select id from cloud.user_ip_address ip where uip.public_ip_address = ip.public_ip_address and ip.data_center_id = uip.zone_id)"); + ) { pstmt.executeUpdate(); - pstmt.close(); s_logger.debug("Upgraded cloud_usage usage_ip_address with Id"); - } catch (Exception e) { throw new CloudRuntimeException("Failed to upgrade usage_ip_address: ", e); }