Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Book getBookById(String book_id) {
- //<editor-fold defaultstate="collapsed" desc="GET BOOK BY BOOK-ID">
- Connection con = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- Book b = null;
- try {
- con = getConnection();
- String query = ("SELECT * FROM book WHERE book_id=" + book_id + ";");
- ps = con.prepareStatement(query);
- rs = ps.executeQuery();
- if (rs.next()) {
- b = new Book(rs.getInt("book_id"), rs.getString("bookTitle"), rs.getString("bookAuthor"), rs.getString("bookDesc"), rs.getInt("publish_year"), rs.getInt("stock"));
- }
- } catch (SQLException e) {
- System.out.println("Exception occured in the getBookById() method: " + e.getMessage());
- } finally {
- try {
- if (rs != null) {
- rs.close();
- }
- if (ps != null) {
- ps.close();
- }
- if (con != null) {
- freeConnection(con);
- }
- } catch (SQLException e) {
- System.out.println("Exception occured in the finally section of the getBookById() method: " + e.getMessage());
- }
- }
- return b;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement