Update try catch to use try with resources

feature/appm-store/pbac
Yohan Avishke 5 years ago
parent 4378feedde
commit f6976800f5

@ -431,23 +431,21 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO {
@Override @Override
public void deleteDeviceType(int tenantID, int deviceTypeId) throws DeviceManagementDAOException { public void deleteDeviceType(int tenantID, int deviceTypeId) throws DeviceManagementDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null;
try {
conn = getConnection();
String sql = "DELETE FROM DM_DEVICE_TYPE" + String sql = "DELETE FROM DM_DEVICE_TYPE" +
" WHERE" + " WHERE" +
" ID = ?" + " ID = ?" +
" AND PROVIDER_TENANT_ID = ?"; " AND PROVIDER_TENANT_ID = ?";
stmt = conn.prepareStatement(sql); try {
conn = getConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, deviceTypeId); stmt.setInt(1, deviceTypeId);
stmt.setInt(2, tenantID); stmt.setInt(2, tenantID);
stmt.execute(); stmt.execute();
}
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementDAOException( throw new DeviceManagementDAOException(
"Error occurred while deleting device type of id: " + deviceTypeId + "Error occurred while deleting device type of id: " + deviceTypeId +
" for tenant: " + tenantID, e); " for tenant: " + tenantID, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, null);
} }
} }

Loading…
Cancel
Save