From 9891b92c32886c7f802dd68d79183be24fdb9adb Mon Sep 17 00:00:00 2001 From: Sergey Iryupin Date: Mon, 1 Jul 2024 08:15:07 +0200 Subject: [PATCH] java pizza project #2 update --- .../repository/db/ExtComponentDbRepository.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/BerlinAIT/Cohort42.1project/JavaPizzaMvn/src/main/java/pizza/repository/db/ExtComponentDbRepository.java b/BerlinAIT/Cohort42.1project/JavaPizzaMvn/src/main/java/pizza/repository/db/ExtComponentDbRepository.java index 42999ac9..19335191 100644 --- a/BerlinAIT/Cohort42.1project/JavaPizzaMvn/src/main/java/pizza/repository/db/ExtComponentDbRepository.java +++ b/BerlinAIT/Cohort42.1project/JavaPizzaMvn/src/main/java/pizza/repository/db/ExtComponentDbRepository.java @@ -1,5 +1,6 @@ package pizza.repository.db; +import pizza.domain.Customer; import pizza.domain.ExtComponent; import pizza.repository.CrudRepository; @@ -70,7 +71,19 @@ public ExtComponent save(ExtComponent component) { @Override public ExtComponent findById(Integer id) { - return null; + ExtComponent component = null; + try (Connection connection = DriverManager.getConnection(dbName); + PreparedStatement ps = connection.prepareStatement(SQL_FIND_BY_ID)) { + ps.setInt(1, id); + ResultSet rs = ps.executeQuery(); + if (rs.next()) { + component = new ExtComponent(rs.getString("name"), rs.getInt("price")); + component.setId(rs.getInt("id")); + } + return component; + } catch (SQLException e) { + throw new RuntimeException(e); + } } @Override