/** * Import books * * @param nodes * @return */ private Boolean processBooks(NodeList nodes) { NodeList books = nodes.item(0).getChildNodes(); for (int i = 0; i < books.getLength(); i++) { if (books.item(i).getNodeType() == Node.ELEMENT_NODE) { Element bookNode = (Element) books.item(i); Book book = new Book(); book.setIdbook(Integer.parseInt(getTagValue("idbook", bookNode))); book.setCode(getTagValue("code", bookNode)); book.setEdition(Integer.parseInt(getTagValue("edition", bookNode))); book.setPages(Integer.parseInt(getTagValue("pages", bookNode))); book.setPlace(getTagValue("place", bookNode)); book.setYear(DatatypeConverter.parseDateTime(getTagValue("year", bookNode)).getTime()); book.setType(getTagValue("type", bookNode)); book.setName(getTagValue("name", bookNode)); // find and set publisher Publisher publisher = publisherMgr.findByIdpublisher(Integer.parseInt(getTagValue("publisher", bookNode))); if (publisher == null) { continue; } book.setPublisher(publisher); // find and set genre Genre genre = genreMgr.findByIdgenre(Integer.parseInt(getTagValue("genre", bookNode))); if (genre == null) { continue; } book.setGenre(genre); // setup book authors List<String> authors = getTagsValues("authorCollection", bookNode); if (book.getAuthorCollection() == null) { book.setAuthorCollection(new ArrayList<Author>()); } for (String authorId : authors) { Author author = authorMgr.findByIdauthor(Integer.parseInt(authorId)); if (author != null) { // book.getAuthorCollection().add(author); author.getBooksCollection().add(book); authorMgr.save(author); } } try { bookMgr.save(book); } catch (EJBException ex) { ex.printStackTrace(System.out); } } } return true; }
// 신간 리스트 public List<Book> SelectNewDataList(int beginRow, int endRow, String month) { // 랭킹을 이용하여 모든 데이터를 조회한다. PreparedStatement pstmt = null; ResultSet rs = null; String sql = "select bookcode, name, volume, writer, publisher, pubdate, genre, image, bookstat, bookstory, ranking "; sql += " from "; sql += " ( "; sql += " select bookcode, name, volume, writer, publisher, pubdate, genre, image, bookstat, bookstory, rank() over( order by name asc, volume desc, bookcode desc) as ranking "; sql += " from books "; sql += " where bookstat != '대출 불가' and pubdate between " + month; sql += " ) "; sql += " where ranking between ? and ? "; List<Book> lists = new ArrayList<Book>(); try { // if( this.conn == null ){ this.conn = this.getConn(); // } pstmt = this.conn.prepareStatement(sql); pstmt.setInt(1, beginRow); pstmt.setInt(2, endRow); rs = pstmt.executeQuery(); while (rs.next()) { Book bean = new Book(); bean.setBookcode(rs.getInt("bookcode")); bean.setName(rs.getString("name")); bean.setVolume(rs.getInt("volume")); bean.setWriter(rs.getString("writer")); bean.setPublisher(rs.getString("publisher")); bean.setPubdate(String.valueOf(rs.getDate("pubdate"))); bean.setGenre(rs.getString("genre")); bean.setImage(rs.getString("image")); bean.setBookstat(rs.getString("bookstat")); bean.setBookstory(rs.getString("bookstory")); lists.add(bean); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (rs != null) { rs.close(); } if (pstmt != null) { pstmt.close(); } this.closeConn(); } catch (Exception e2) { e2.printStackTrace(); } } return lists; }
// 책 1건에 대한 상세 정보 보기 public Book SelectDataByPk(int bookcode) { PreparedStatement pstmt = null; ResultSet rs = null; String sql = "select * "; sql += " from books "; sql += " where bookcode = ? "; Book bean = null; try { if (this.conn == null) { this.conn = this.getConn(); } pstmt = this.conn.prepareStatement(sql); // placehodelr 치환은 반드시 execute 메소드 실행 바로 직전에 하세요. pstmt.setInt(1, bookcode); rs = pstmt.executeQuery(); if (rs.next()) { bean = new Book(); bean.setBookcode(rs.getInt("bookcode")); bean.setName(rs.getString("name")); bean.setVolume(rs.getInt("volume")); bean.setWriter(rs.getString("writer")); bean.setPublisher(rs.getString("publisher")); bean.setPubdate(String.valueOf(rs.getDate("pubdate"))); bean.setGenre(rs.getString("genre")); bean.setImage(rs.getString("image")); bean.setBookstat(rs.getString("bookstat")); bean.setBookstory(rs.getString("bookstory")); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (rs != null) { rs.close(); } if (pstmt != null) { pstmt.close(); } this.closeConn(); } catch (Exception e2) { e2.printStackTrace(); } } return bean; }
private void createBooks() { Book book = new Book(); book.setTitle("Java Programming 24-Hour Trainer"); book.setAuthor("Yakov Fain"); book.setGenre(Genre.PROGRAMMING); addToLibrary(book); book = new Book(); book.setTitle("Thinking in Java"); book.setAuthor("Bruce Eckel"); book.setGenre(Genre.PROGRAMMING); addToLibrary(book); book = new Book(); book.setTitle("Nineteen Eighty-Four"); book.setAuthor("George Orwell"); book.setGenre(Genre.FICTION); addToLibrary(book); book = new Book(); book.setTitle("Great Gatsby"); book.setAuthor("F. Scott Fitzgerald"); book.setGenre(Genre.FICTION); addToLibrary(book); book = new Book(); book.setTitle("Girl with the Dragon Tattoo"); book.setAuthor("Stieg Larsson"); book.setGenre(Genre.FICTION); addToLibrary(book); book = new Book(); book.setTitle("Eat Move Sleep"); book.setAuthor("Tom Rath"); book.setGenre(Genre.FOOD); addToLibrary(book); book = new Book(); book.setTitle("Stalingrad: The Fateful Siege"); book.setAuthor("Antony Beevor"); book.setGenre(Genre.HISTORY); addToLibrary(book); book = new Book(); book.setTitle("Battle Of Britain: Myth and Reality"); book.setAuthor("Richard Overy"); book.setGenre(Genre.HISTORY); addToLibrary(book); book = new Book(); book.setTitle("Why the Allies Won"); book.setAuthor("Richard Overy"); book.setGenre(Genre.HISTORY); addToLibrary(book); book = new Book(); book.setTitle("Fellowship of the Ring"); book.setAuthor("J.R.R. Tolkien"); book.setGenre(Genre.FANTASY); addToLibrary(book); book = new Book(); book.setTitle("Hobbit"); book.setAuthor("J.R.R. Tolkien"); book.setGenre(Genre.FANTASY); addToLibrary(book); }