@Override public Project get(int id) { Project result = null; try (Connection connection = dbDataSourceProvider.getConnection()) { try (PreparedStatement statement = connection.prepareStatement(sqlProvider.get4Load())) { statement.setInt(1, id); ResultSet resultSet = statement.executeQuery(); if (resultSet.next()) { result = new Project( resultSet.getString("name"), resultSet.getInt("goal"), resultSet.getDate("deadline_date")); result.setShortDescription(resultSet.getString("description")); result.setBalance(resultSet.getInt("balance")); result.setDemoLink(resultSet.getString("demo_link")); result.setCreateDate(resultSet.getDate("create_date")); result.setId(id); } } connection.commit(); } catch (SQLException e) { throw new RuntimeException(e); } return result; }
@Override public List<Project> fetch(int categoryId) { List<Project> result = new ArrayList<>(); try (Connection connection = dbDataSourceProvider.getConnection(); PreparedStatement statement = connection.prepareStatement(sqlProvider.get4Fetch())) { statement.setInt(1, categoryId); ResultSet resultSet = statement.executeQuery(); while (resultSet.next()) { Project project = new Project( resultSet.getString("project_name"), resultSet.getInt("goal"), resultSet.getDate("deadline_date")); project.setShortDescription(resultSet.getString("short_description")); project.setId(resultSet.getInt("id")); project.setBalance(resultSet.getInt("balance")); result.add(project); } connection.commit(); } catch (SQLException e) { throw new RuntimeException(e); } return result; }