public User getUser(long userId) { User user = null; try { Class.forName("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 = "Select * from User where id = " + userId; ResultSet rs = stmt.executeQuery(query); while (rs.next()) { long id = rs.getLong("id"); String email = rs.getString("email"); String password = rs.getString("password"); String firstName = rs.getString("first_name"); String lastName = rs.getString("last_name"); int gender_id = rs.getInt("gender_id"); Gender gender = Gender.values()[gender_id]; int user_type_id = rs.getInt("user_type_id"); UserType userType = UserType.values()[user_type_id]; user = UserManager.getInstance().createUser(id, email, password, firstName, lastName, gender, userType); } } catch (SQLException e) { e.printStackTrace(); } return user; } public Bookmark getBook(long bookId) { Book book = null; try { Class.forName("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 = "Select b.id, title, image_url, publication_year, p.name, GROUP_CONCAT(a.name SEPARATOR ',') AS authors, book_genre_id, amazon_rating, created_date" + " from Book b, Publisher p, Author a, Book_Author ba " + "where b.id = " + bookId + " and b.publisher_id = p.id and b.id = ba.book_id and ba.author_id = a.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 + ", publisher: " + publisher + ", authors: " + String.join(", ", authors) + ", genre: " + genre + ", amazonRating: " + amazonRating); book = BookmarkManager.getInstance().createBook(id, title, imageUrl, publicationYear, publisher, authors, genre, amazonRating/*, values[7]*/); } } catch (SQLException e) { e.printStackTrace(); } return book; }