I have to write a code for searcing books in library and i have written but it is not displaying the result.I don't know where i have gone wrong.Also i want to know if there is any better idea then this and what type of validations i can give.I have written code as shown below.
search.html
<body> <form name="search" action="http://localhost:8080/examples/jsp/searchbook.jsp" method="post"> <table align="center"> <tr> <td> Select any field </td> <td> <select name="keyfield" > <option> title</option> <option> author </option> <option> category </option> <option>pub_year</option> </select> </td> </tr> <tr> <td> Enter the keyword: </td> <td><input type="text" name="keyword" /> </td> </tr> <tr> <td> <input type="submit" value="Search" /> </td> <td> <input type="reset" value="reset" /></td></tr> </table> </form> </body> <strong>search.jsp</strong> <body> <table border=2> <tr> <th>acc<em>no </th><th>title</th> <th>category</th><th> no</em>of<em>copies </th> <th> edition </th> <th> pub</em>year</th> <th> price </th> </tr> <% String keyfield=request.getParameter("keyfield"); String keyword=request.getParameter("keyword"); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:dms"," smartlib","smartlib"); Statement stmt1=con.createStatement(); ResultSet rs=stmt1.executeQuery("SELECT a.accno,a.title,a.category,a.no_of_copies,b.edition,c.pub_year,d.price from book_det a,edition b,publication c,price d where (a.accno=b.accno and a.accno=c.accno and a.accno=d.accno) and ('"+keyfield+"'='"+keyword+"')"); while (rs.next()) { %> <tr> <td> <%=rs.getString(1)%> </td> <td> <%=rs.getString(2)%> </td> <td> <%=rs.getString(3)%> </td> <td> <%=rs.getString(4)%> </td> <td> <%=rs.getString(5)%> </td> <td> <%=rs.getString(6)%> <td> <%=rs.getString(7)%> </td> </tr> <%} rs.close(); stmt1.close(); con.close(); } catch(ClassNotFoundException cnfe){out.println(cnfe.getMessage());} catch(java.sql.SQLException sqle){out.println(sqle.getMessage());} %> </body> </html> Thank u in advance
Ads