Пример #1
0
    @Override
    public Book mapRow(ResultSet rs, int rowNum) throws SQLException {
      Book book = new Book();
      book.setIsbn(rs.getString("ISBN"));
      book.setTitle(rs.getString("title"));
      book.setDescription(rs.getString("description"));
      book.setPrice(rs.getDouble("price"));
      book.setPublisher(rs.getString("publisher"));
      book.setPubDate(rs.getDate("pubdate"));
      book.setEdition(rs.getInt("edition"));
      book.setPages(rs.getInt("pages"));
      book.setStock(rs.getInt("stock"));
      book.setCategories(getCategoriesbyIsbn(book.getIsbn()));
      book.setAuthors(getAuthorsbyIsbn(book.getIsbn()));

      return book;
    }
Пример #2
0
  public static List<Book> searchBook(String key) {

    String sql = "exec searchBook '" + key + "'";
    Result result = DBHelper.execSql(sql);
    SortedMap[] rows = result.getRows();
    List<Book> books = new ArrayList<Book>();

    for (SortedMap row : rows) {
      Book book = new Book();
      book.setId(Integer.parseInt(row.get("id").toString().trim()));
      book.setName(row.get("name").toString().trim());
      book.setISBN(row.get("ISBN").toString().trim());
      book.setAuthor(row.get("author").toString().trim());
      book.setDescription(row.get("description").toString().trim());
      book.setPublishDate(row.get("publishDate").toString().trim());
      book.setQuantity(Integer.parseInt(row.get("quantity").toString().trim()));
      System.out.println(book);
      books.add(book);
    }

    return books;
  }