@Override public List extractData(ResultSet rs) throws Exception { List<Genre> genre = new ArrayList<Genre>(); while (rs.next()) { Genre a = new Genre(); a.setGenreId(rs.getInt("genre_id")); a.setGenreName(rs.getString("genre_name")); genre.add(a); } return genre; }
private void Deletegenre() throws SQLException { boolean exit_Add = false; int id; Map<Integer, String> m = as.listGenre2(); System.out.println("\nGenre ID | Genre Name "); System.out.println("---------------------------------------"); for (Map.Entry<Integer, String> map : m.entrySet()) { System.out.println(map.getKey() + "\t " + map.getValue()); } do { System.out.println("Enter the Genre Id you want to delete:"); try { id = Integer.parseInt(sc.nextLine().trim()); if (m.containsKey(id)) { Genre g = new Genre(); g.setGenreId(id); as.deleteGenre(g); System.out.println("Deleted successfuly"); } else { System.out.println("This Id does not exist."); } } catch (Exception e) { System.out.println("INFO:Should be an integer!"); } if (!exit_Add) { System.out.println(); System.out.println(); System.out.println("Press ' q ' to return or any other key to continue"); String option = (sc.nextLine()); if (option.length() > 0) { switch (option.charAt(0)) { case 'q': exit_Add = true; break; default: exit_Add = false; break; } } } } while (!exit_Add); }
private void Updategenre2(int id) throws SQLException { boolean exit_Add = false; Map<Integer, String> m = as.listGenre2(); String name; do { System.out.println(); System.out.println("Enter the new Genre Name:"); name = sc.nextLine(); if (!m.containsKey(name)) { Genre g = new Genre(); g.setGenreId(id); g.setGenreName(name); try { as.updateGenre(g); System.out.println("Update successful"); exit_Add = true; } catch (Exception e) { System.out.println(e.getMessage()); } } else { System.out.println("Update successful"); } if (!exit_Add) { System.out.println(); System.out.println(); System.out.println("Press ' q ' to return or any other key to continue"); String option = (sc.nextLine()); if (option.length() > 0) { switch (option.charAt(0)) { case 'q': exit_Add = true; break; default: exit_Add = false; break; } } } } while (!exit_Add); }
@Override public List extractData(ResultSet rs) throws Exception { List<Genre> genres = new ArrayList<Genre>(); BookDAO bdao = new BookDAO(getConnection()); while (rs.next()) { Genre g = new Genre(); g.setGenreId(rs.getInt("genre_id")); g.setGenreName(rs.getString("genre_name")); @SuppressWarnings("unchecked") List<Book> books = (List<Book>) bdao.readFirstLevel( "select * from tbl_book where bookId In" + "(select bookId from tbl_book_genres where genreId=?)", new Object[] {rs.getInt("genreId")}); genres.add(g); } return genres; }