Advertisement
Guest User

northwind

a guest
Apr 2nd, 2016
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <%--
  2. Document : query
  3. Created on : Mar 19, 2016, 6:43:52 PM
  4. Author : hisham
  5. --%>
  6.  
  7. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  8. <!DOCTYPE html>
  9. <html>
  10. <head>
  11. <title>PRODUCT</title>
  12. </head>
  13. <body>
  14. <h1>Product Search</h1>
  15. <h3>Enter Category:</h3>
  16. <form method="get">
  17. <input type="text" name="txtCategory" value="">
  18. <input type="submit" value="SEARCH">
  19. </form>
  20.  
  21. <%
  22. String Strcategory = request.getParameter("txtCategory");
  23. if (Strcategory != null) {
  24. %>
  25. <%@ page import = "java.sql.*" %>
  26. <%
  27. Connection conn = DriverManager.getConnection(
  28. "jdbc:mysql://localhost:3306/northwind", "root", ""); // <== Check!
  29. // Connection conn =
  30. // DriverManager.getConnection("jdbc:odbc:eshopODBC"); // Access
  31. Statement stmt = conn.createStatement();
  32.  
  33. String sqlStr = "SELECT * FROM categories WHERE CategoryName Like ";
  34. sqlStr += "'%" + Strcategory + "%'"; // First author
  35. ResultSet rset = stmt.executeQuery(sqlStr);
  36. int category = 0;
  37. while (rset.next())
  38. {
  39. category = rset.getInt("CategoryID");
  40. Strcategory = rset.getString("CategoryName");
  41. }
  42. //sqlStr += " AND qty > 0 ORDER BY author ASC, title ASC";
  43.  
  44. String sqlStr2 = "SELECT ProductId, ProductName, FROM products WHERE CategoryID=";
  45. sqlStr2 += "" + category + ""; // First author
  46.  
  47. // for debugging
  48. System.out.println("Query statement is " + sqlStr2);
  49. ResultSet rsetProduct = stmt.executeQuery(sqlStr2);
  50. %>
  51. <hr>
  52. <p>search Product for category :<%= Strcategory %></p>
  53. <form method="get" action="order.jsp">
  54. <table border=1 cellpadding=5>
  55. <tr>
  56. <th>Category</th>
  57. <th>Category</th>
  58.  
  59. </tr>
  60. <%
  61. while (rset.next()) {
  62. int id = rset.getInt("ProductID");
  63. %>
  64. <tr>
  65. <td><input type="checkbox" name="id" value="<%= id %>"></td>
  66. <td><%= rset.getString("ProductID") %></td>
  67. <td><%= rset.getString("ProductName") %></td>
  68.  
  69. </tr>
  70. <%
  71. }
  72. %>
  73. </table>
  74. <br>
  75. <input type="submit" value="Order">
  76. <input type="reset" value="Clear">
  77. </form>
  78. <a href="<%= request.getRequestURI() %>"><h3>Back</h3></a>
  79. <%
  80. rset.close();
  81. stmt.close();
  82. conn.close();
  83. }
  84. %>
  85. </body>
  86. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement