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; String sql = "DELETE FROM DM_DEVICE_TYPE" +
" WHERE" +
" ID = ?" +
" AND PROVIDER_TENANT_ID = ?";
try { try {
conn = getConnection(); conn = getConnection();
String sql = "DELETE FROM DM_DEVICE_TYPE" + try (PreparedStatement stmt = conn.prepareStatement(sql)) {
" WHERE" + stmt.setInt(1, deviceTypeId);
" ID = ?" + stmt.setInt(2, tenantID);
" AND PROVIDER_TENANT_ID = ?"; stmt.execute();
stmt = conn.prepareStatement(sql); }
stmt.setInt(1, deviceTypeId);
stmt.setInt(2, tenantID);
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