public Collection getBooks(boolean isBookmarked, long userId) { Collection result = new ArrayList<>(); try { Class.forName("com.mysql.jdbc.Driver"); //new com.mysql.jdbc.Driver(); // OR //System.setProperty("jdbc.drivers", "com.mysql.jdbc.Driver"); // OR java.sql.DriverManager //DriverManager.registerDriver(new com.mysql.jdbc.Driver()); } catch (ClassNotFoundException e) { e.printStackTrace(); } try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jid_thrillio?useSSL=false", "root", "root"); Statement stmt = conn.createStatement();) { String query = ""; if (!isBookmarked) { query = "Select b.id, title, image_url, publication_year, GROUP_CONCAT(a.name SEPARATOR ',') AS authors, book_genre_id, " + "amazon_rating from Book b, Author a, Book_Author ba where b.id = ba.book_id and ba.author_id = a.id and " + "b.id NOT IN (select ub.book_id from User u, User_Book ub where u.id = " + userId + " and u.id = ub.user_id) group by b.id"; } /*else { query = "Select b.id, title, image_url, publication_year, GROUP_CONCAT(a.name SEPARATOR ',') AS authors, book_genre_id, " + "amazon_rating from Book b, Author a, Book_Author ba where b.id = ba.book_id and ba.author_id = a.id and " + "b.id IN (select ub.book_id from User u, User_Book ub where u.id = " + userId + " and u.id = ub.user_id) group by b.id"; }*/ ResultSet rs = stmt.executeQuery(query); while (rs.next()) { long id = rs.getLong("id"); String title = rs.getString("title"); String imageUrl = rs.getString("image_url"); int publicationYear = rs.getInt("publication_year"); //String publisher = rs.getString("name"); String[] authors = rs.getString("authors").split(","); int genre_id = rs.getInt("book_genre_id"); BookGenre genre = BookGenre.values()[genre_id]; double amazonRating = rs.getDouble("amazon_rating"); System.out.println("id: " + id + ", title: " + title + ", publication year: " + publicationYear + ", authors: " + String.join(", ", authors) + ", genre: " + genre + ", amazonRating: " + amazonRating); Bookmark bookmark = BookmarkManager.getInstance().createBook(id, title, imageUrl, publicationYear, null, authors, genre, amazonRating/*, values[7]*/); result.add(bookmark); } } catch (SQLException e) { e.printStackTrace(); } return result; }