private boolean categoryExists(int id_category) {
Collection<Category> categories = commonRepository.loadCategoriesFromDatabase();
for (Category category : categories) {
if (category.getId_category() == id_category) {
return true;
}
}
return false;
}
Pierwsza myśl -> szkoda że nie używasz streamów
Druga myśl -> yyyyyy ... czy ty tutaj ładujesz całą tabelę do pamięci tylko po to żeby sprawdzić że rekord istnieje?
public Collection<Customer> loadCustomersFromDatabase() {
Collection<Customer> customers = new ArrayList<>();
String sql = "SELECT * FROM Customers c JOIN Customers_password cp ON c.id_customer = cp.customer_id";
try (Statement statement = database.getConnection().createStatement()) {
ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
customers.add(mapResultSetToCustomer(resultSet));
}
} catch (SQLException e) {
e.printStackTrace();
}
return customers;
}
Dalej nie sprawdzam. Przerób to tak żeby baza szukałą zamiast ciebie. Słowo kluczowe w SQLu to WHERE