コード例 #1
0
ファイル: BookDAO.java プロジェクト: raygomez/pealib
  public static int addBook(Book book) throws Exception {
    int intStat = 0;

    if (null != book.getIsbn10()) {
      book.setIsbn13(IsbnUtil.convert(book.getIsbn10()));
    } else {
      book.setIsbn10(IsbnUtil.convert(book.getIsbn13()));
    }

    String sql =
        "INSERT INTO Books (ISBN10, ISBN13, Title, Author, "
            + "Edition, Publisher, Description, YearPublish, "
            + "Copies) VALUES (?,?,?,?,?,?,?,?,?)";

    PreparedStatement ps = Connector.getConnection().prepareStatement(sql);
    ps.setString(1, book.getIsbn10());
    ps.setString(2, book.getIsbn13());
    ps.setString(3, book.getTitle());
    ps.setString(4, book.getAuthor());
    ps.setString(5, book.getEdition());
    ps.setString(6, book.getPublisher());
    ps.setString(7, book.getDescription());
    ps.setInt(8, book.getYearPublish());
    ps.setInt(9, book.getCopies());

    intStat = ps.executeUpdate();

    Connector.close();

    return intStat;
  }
コード例 #2
0
ファイル: BookDAO.java プロジェクト: raygomez/pealib
  public static boolean isIsbnExisting(String isbn) throws Exception {
    boolean validate = false;

    String otherISBN = IsbnUtil.convert(isbn);
    String sql = "";
    PreparedStatement ps = null;

    if (otherISBN == null) {
      // otherISBN is ISBN10 and is not existing
      sql = "SELECT COUNT(*) From Books WHERE Isbn13 = ?";
      ps = Connector.getConnection().prepareStatement(sql);
      ps.setString(1, isbn);
    } else {

      sql = "SELECT COUNT(*) From Books WHERE Isbn13 = ? and Isbn10 = ?";
      ps = Connector.getConnection().prepareStatement(sql);

      if (isbn.length() == 13) {
        ps.setString(1, isbn);
        ps.setString(2, otherISBN);
      } else {
        // argument is ISBN10
        ps.setString(1, otherISBN);
        ps.setString(2, isbn);
      }
    }

    ResultSet rs = ps.executeQuery();
    rs.first();
    if (rs.getInt(1) > 0) {
      validate = true;
    }
    Connector.close();
    return validate;
  }