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

connected to DB, implemented DAO #370

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

Conversation

Zartones
Copy link

No description provided.

book.setTitle("GCSE Computer Science OCR Complete Revision");
book.setPrice(BigDecimal.valueOf(400));
bookDao.create(book);
System.out.println(bookDao.findById(6L));

Choose a reason for hiding this comment

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

You don't have book with id 6 becuase you have only one book

book.setPrice(BigDecimal.valueOf(400));
bookDao.create(book);
System.out.println(bookDao.findById(6L));
System.out.println(bookDao.deleteById(6L));

Choose a reason for hiding this comment

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

the same


public static void main(String[] args) {
BookDao bookDao = (BookDao) injector.getInstance(BookDao.class);
Book book = new Book();

Choose a reason for hiding this comment

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

Create several books (List) and implement daoImpl methods


@Dao
public class BookDaoImpl implements BookDao {

Choose a reason for hiding this comment

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

Suggested change

statement.setLong(1, id);
ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
String title = resultSet.getString("title");

Choose a reason for hiding this comment

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

Create separate method for mapping resultSet to Book

@@ -0,0 +1,131 @@
package mate.academy.lib;

Choose a reason for hiding this comment

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

Suggested change
package mate.academy.lib;
package mate.academy.dao;

@@ -0,0 +1,28 @@
package mate.academy.lib;

Choose a reason for hiding this comment

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

Suggested change
package mate.academy.lib;
package mate.academy.util;

@@ -0,0 +1,7 @@
package mate.academy.lib;

Choose a reason for hiding this comment

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

Suggested change
package mate.academy.lib;
package mate.academy.exception;

@@ -0,0 +1,22 @@
CREATE TABLE `books` (
`id` INT 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` INT NOT NULL AUTO_INCREMENT,
`id` BIGINT AUTO_INCREMENT,

CREATE TABLE `books` (
`id` INT 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.

Use mysql type for BigDecimal

Choose a reason for hiding this comment

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

not fixed

Comment on lines 21 to 23
try (Connection connection = ConnectionUtil.getConnection();
PreparedStatement statement =
connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {

Choose a reason for hiding this comment

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

try with resources use for read ioperations

DB_PROPERTIES.put("password", "1987");

try {
Class.forName("com.mysql.cj.jdbc.Driver");

Choose a reason for hiding this comment

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

better save to constant

CREATE TABLE `books` (
`id` INT 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.

not fixed

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