From f6976800f5cdff1bf22ba336f727a7c6baaecac6 Mon Sep 17 00:00:00 2001 From: Yohan Avishke Date: Thu, 9 Jan 2020 11:20:13 +0530 Subject: [PATCH] Update try catch to use try with resources --- .../mgt/core/dao/impl/DeviceTypeDAOImpl.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java index 5084428ce9..68a029c90e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java @@ -431,23 +431,21 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { @Override public void deleteDeviceType(int tenantID, int deviceTypeId) throws DeviceManagementDAOException { Connection conn; - PreparedStatement stmt = null; + String sql = "DELETE FROM DM_DEVICE_TYPE" + + " WHERE" + + " ID = ?" + + " AND PROVIDER_TENANT_ID = ?"; try { conn = getConnection(); - String sql = "DELETE FROM DM_DEVICE_TYPE" + - " WHERE" + - " ID = ?" + - " AND PROVIDER_TENANT_ID = ?"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, deviceTypeId); - stmt.setInt(2, tenantID); - stmt.execute(); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setInt(1, deviceTypeId); + stmt.setInt(2, tenantID); + stmt.execute(); + } } catch (SQLException e) { throw new DeviceManagementDAOException( "Error occurred while deleting device type of id: " + deviceTypeId + " for tenant: " + tenantID, e); - } finally { - DeviceManagementDAOUtil.cleanupResources(stmt, null); } }