public License updateLicense(License license) throws SQLException { try (Connection conn = ds.getConnection()) { PreparedStatement statement = conn.prepareStatement( "UPDATE License SET " + "releaseId = ?, state = ?, licenseTypeId = ?, latestDeliveryDate = ? WHERE id = ?;"); State licenseState = license.getState(); statement.setObject(1, license.getRelease() == null ? null : license.getRelease().getId()); statement.setInt(2, licenseState.getStateNumber()); statement.setInt(3, license.getType().getId()); statement.setObject( 4, license.getLatestDeliveryDate() == null ? null : license.getLatestDeliveryDate()); statement.setInt(5, license.getId()); int rowCount = statement.executeUpdate(); if (rowCount == 0) { throw new RuntimeException("No license with id: " + license.getId()); } } return license; }