Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added solution #81

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

added solution #81

wants to merge 5 commits into from

Conversation

Visqe
Copy link

@Visqe Visqe commented Aug 14, 2023

No description provided.

public static Connection getConnection() throws SQLException {
return DriverManager.getConnection("jdbc:mysql://localhost:3306/booksDB", DB_Properties);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add empty line to the end of file

Book update(Book book);

boolean deleteById(Long id);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add empty line to the end of file

Comment on lines 28 to 30
if (updates < 1) {
throw new DataProcessingException("Error during creating book " + book);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you do not need this check, affect zero rows - is okay

Comment on lines 82 to 84
if (updates < 1) {
throw new DataProcessingException("Error during updating book " + book);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

public DataProcessingException(String message) {
super(message);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add empty line to the end of file

", price=" + price +
'}';
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add empty line to the end of file

Copy link

@nacenik nacenik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good solution, let's improve it a little bit :)

Comment on lines 75 to 77
statement.setString(1, book.getTitle());
statement.setBigDecimal(2, book.getPrice());
statement.setLong(3, book.getId());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create constants for magic numbers and reuse them

statement.setLong(3, book.getId());
statement.executeUpdate();
} catch (SQLException e) {
throw new DataProcessingException("Can not update book in table", e);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which book? Add more info

@@ -0,0 +1,26 @@
package mate.academy;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend you create separate package for util classes

book.setId(resultSet.getObject(1, Long.class));
}
} catch (SQLException e) {
throw new DataProcessingException("Cant save book with title = " + book.getTitle(), e);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print all info about book that cannot be saved

statement.setLong(1, id);
return statement.executeUpdate() > 0;
} catch (SQLException e) {
throw new RuntimeException("Can not delete book by id " + id, e);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new RuntimeException("Can not delete book by id " + id, e);
throw new RuntimeException("Cannot delete book by id " + id, e);

CREATE TABLE `books` (
`id` INT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(255),
`price` INT,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Int? How do you want to put a big decimal into the int?

Copy link

@andrii-hoienko andrii-hoienko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants