Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ManagerBook.java (which is the DAO)
- public Book findBook(int isbn) throws SQLException, ClassNotFoundException{
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection(url, user, password);
- String find = "SELECT * from book WHERE isbn = ?";
- PreparedStatement stt = con.prepareStatement(find);
- stt.setInt(1, isbn);
- ResultSet rs = stt.executeQuery();
- Book b1 = new Book();
- if (rs.next()) {
- int isbn1 = rs.getInt("isbn");
- String title = rs.getString("title");
- b1.setIsbn(isbn1);
- b1.setTitle(title);
- }
- con.close();
- stt.close();
- rs.close();
- return b1;
- }
- find.jsp
- <jsp:useBean id = "bm" class="book.ManagerBook" scope = "session"/>
- <h1> Welcome to ABC Library</h1>
- <form>
- <table>
- <tr>
- <td> Enter Details </td>
- <td><input type="text" name="isbn"></td>
- <td><input type="submit" name="find" value="find"></td>
- </tr>
- </table>
- <input type="hidden" name="submitted" value="true">
- </form>
- <%
- Boolean submitted = Boolean.parseBoolean(request.getParameter("submitted"));
- if(submitted){
- int isbn = Integer.parseInt(request.getParameter("isbn"));
- Book b2 = bm.findBook(isbn);
- %>
- <table>
- <tr>
- <td colspan=2>
- <h2>Book Found</h2>
- </td>
- </tr>
- <tr>
- <td><h3>ISBN</h3></td>
- <td><h3>Title</h3></td>
- </tr>
- <tr>
- <td><%= b2.getIsbn()%></td>
- <td><%= b2.getTitle() %></td>
- </tr>
- </table>
- <%}else if(!submitted){ %>
- <h3> Book Not Found</h3>
- <% } %>
Advertisement
Add Comment
Please, Sign In to add comment