Skip to content

Commit

Permalink
Updated CarRepository.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Alina Tarasova committed Jul 5, 2024
1 parent e1dc049 commit 57e1e51
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void save(Car car) throws SQLException {
var preparedStatement = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
preparedStatement.setString(1, car.getMake());
preparedStatement.setString(2, car.getModel());
Instant createdAt = Instant.now();
var createdAt = Instant.now();
preparedStatement.setTimestamp(3, Timestamp.from(createdAt));

preparedStatement.executeUpdate();
Expand All @@ -41,8 +41,11 @@ public static Optional<Car> find(Long id) throws SQLException {
if (resultSet.next()) {
var make = resultSet.getString("make");
var model = resultSet.getString("model");
var createdAt = resultSet.getTimestamp("created_at").toInstant();

var car = new Car(make, model);
car.setId(id);
car.setCreatedAt(createdAt);
return Optional.of(car);
}
return Optional.empty();
Expand Down

0 comments on commit 57e1e51

Please sign in to comment.