Git Product home page Git Product logo

jv-jdbc-intro's Introduction

Task description

Your task is to create a Book entity class and BookDao repository interface, and it's implementation.

Here are the steps you need to do in this HW:

  • Establish connection to your Database. Be sure you have installed DB and you are able to create a new schema for this task.
  • Create init_db.sql file in src/main/resources folder. In this file, put the scripts for creating required table.
  • Create Book model.
  • Create DAO layer for Book model. Below you can see the list of required methods.
  • You're already given an injector and @Dao annotation. Do not forget to use it for Dao implementations.
  • Return Optional when you can return null in DAO. For example: public Optional<Book> findById(Long id);
  • In the main method call all CRUD methods. It may look like:
public class Main {
    private static final Injector injector = Injector.getInstance("YOUR_PACKAGE");

    public static void main(String[] args) {
        BookDao bookDao = (BookDao) injector.getInstance(BookDao.class);
        Book book = new Book();
        // initialize field values using setters or constructor
        BookDao.create(book);
        // test other methods from BookDao
    }
}

WARNING!!! Path to your project must contain only english letters. Also, it mustn't contain spaces. In other case Injector won't work correctly.

  • Your table should be named books and contain these columns: id, title, price.

Java classes structure:

  • Book
import java.math.BigDecimal;

public class Book {
  private Long id;
  private String title;
  private BigDecimal price;
}

BookDao methods:

- Book create(Book book);
- Optional<Book> findById(Long id);
- List<Book> findAll();
- Book update(Book book);
- boolean deleteById(Long id);

Create custom exception

e.printStackTrace() - is a bad practice! Let's create custom exception DataProcessingException and constructor with two parameters: String message and Throwable ex.
It should be extended from RuntimeException. You should rethrow this exception in catch block on dao layer.

DB connection error:

If you can't connect to your db because of this error:
The server time zone value β€˜EEST’ is unrecognized or represents more than one time zone.
Try to set timezone explicitly in your connection URL.
Example:
...localhost:3306/your_schema?serverTimezone=UTC
Or you can set a timezone in MySql directly by running command: SET GLOBAL time_zone = '+3:00';

You can check yourself using this checklist

jv-jdbc-intro's People

Contributors

boroda4436 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.