-
Notifications
You must be signed in to change notification settings - Fork 438
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
base: main
Are you sure you want to change the base?
created connection to DB and implemented DAO methods #374
Conversation
src/main/resources/init_db.sql
Outdated
CREATE TABLE books ( | ||
id BIGINT NOT NULL AUTO_INCREMENT, | ||
title VARCHAR(255), | ||
price INT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
price INT, | |
price DECIMAL(10, 2) NOT NULL |
src/main/resources/init_db.sql
Outdated
@@ -0,0 +1,6 @@ | |||
CREATE TABLE books ( | |||
id BIGINT NOT NULL AUTO_INCREMENT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id BIGINT NOT NULL AUTO_INCREMENT, | |
id BIGINT AUTO_INCREMENT, | |
} | ||
} | ||
|
||
private Book createNewEntity(ResultSet resultSet) throws SQLException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)) { |
There was a problem hiding this comment.
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
No description provided.