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

created connection to DB and implemented DAO methods #374

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

Conversation

YuliiaNisha
Copy link

No description provided.

CREATE TABLE books (
id BIGINT NOT NULL AUTO_INCREMENT,
title VARCHAR(255),
price INT,

Choose a reason for hiding this comment

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

Suggested change
price INT,
price DECIMAL(10, 2) NOT NULL

@@ -0,0 +1,6 @@
CREATE TABLE books (
id BIGINT NOT NULL AUTO_INCREMENT,

Choose a reason for hiding this comment

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

Suggested change
id BIGINT NOT NULL AUTO_INCREMENT,
id BIGINT AUTO_INCREMENT,

}
}

private Book createNewEntity(ResultSet resultSet) throws SQLException {

Choose a reason for hiding this comment

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

Suggested change
private Book createNewEntity(ResultSet resultSet) throws SQLException {
private Book mapResultSetToBook(ResultSet resultSet) throws SQLException {

String sql = "SELECT * FROM books";
List<Book> allBooks = new ArrayList<>();
try (Connection connection = ConnectionUtil.create();
PreparedStatement statement = connection.prepareStatement(sql)) {

Choose a reason for hiding this comment

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

It's more efficient to use Stetament instead of PreparedStatement if there are no ?-parameters

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