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

bookDao methods implemented and tested #343

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

Conversation

almanac1914
Copy link

No description provided.

@@ -0,0 +1,5 @@
CREATE TABLE `books` (
`id` BIGINT AUO_INCREMENT PRIMARY KEY,
`title` VARCHAR(255),

Choose a reason for hiding this comment

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

Not null for title and price

import java.sql.SQLException;
import java.util.Properties;

public class ConnectionUtil {

Choose a reason for hiding this comment

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

replace to util package

PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setLong(1, id);

int affectedRows = statement.executeUpdate();

Choose a reason for hiding this comment

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

Suggested change
int affectedRows = statement.executeUpdate();
return statement.executeUpdate() > 0;

+ " inserted 0 rows", null);
}
} catch (SQLException e) {
throw new DataProcessingException("Failed to add new book: " + book, e);

Choose a reason for hiding this comment

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

wrong message

int affectedRows = statement.executeUpdate();
if (affectedRows < 1) {
throw new DataProcessingException("Expected to insert at least 1 row,"
+ " inserted 0 rows", null);

Choose a reason for hiding this comment

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

Don't put null, create other constructor public DataProcessingException(String message) if needed

try (Connection connection = ConnectionUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setLong(1, id);
try (ResultSet resultSet = statement.executeQuery()) {

Choose a reason for hiding this comment

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

why do you need try block here?

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.

3 participants