Advertisement
Guest User

Untitled

a guest
Oct 26th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  2. <%@page import="java.sql.*"%>
  3. <!DOCTYPE html>
  4.  
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  8. <title>Search Cars</title>
  9. <link href="" type="text/css" rel="stylesheet">
  10. <style>
  11. table, th, td {
  12. border: 1px solid black;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <h1>Search Cars</h1>
  18. <form action= "" method="POST">
  19. <center>
  20. Car Make:
  21. <select name="cartype" id="cartype" onchange="this.form.submit();">
  22. <option value="0">Select Car Make</option>
  23. <%
  24. String carmod= null;
  25. try{
  26. String Query="Select * FROM auction_items GROUP BY cartype";
  27. Class.forName("com.mysql.jdbc.Driver").newInstance();
  28. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/auction","root","cenk");
  29. Statement st= conn.createStatement();
  30. ResultSet rs= st.executeQuery(Query);
  31. while(rs.next()){
  32. %><option value ="<%=rs.getInt("ProductID")%>"
  33.  
  34. <%
  35. if(request.getParameter("cartype") !=null){
  36. if(rs.getInt("ProductID")==Integer.parseInt(request.getParameter("cartype")))
  37. {
  38. out.print("Selected");
  39. carmod=rs.getString("cartype");
  40. }
  41. }
  42.  
  43. %>><%=rs.getString("cartype")%></option><%
  44.  
  45. }
  46.  
  47. }catch(Exception e){
  48. e.printStackTrace();
  49. }
  50.  
  51. %>
  52. </select>
  53. </p>
  54. Car model:
  55. <select name="carmodel" id="carmodel" onchange="this.form.submit();">
  56. <option value="0">Select Car Model</option>
  57. <%
  58. try{
  59. String query="Select * FROM auction_items WHERE cartype=? Group by carmodel";
  60. Class.forName("com.mysql.jdbc.Driver").newInstance();
  61. Connection con= DriverManager.getConnection("jdbc:mysql://localhost/auction","root","cenk");
  62. PreparedStatement psmt=con.prepareStatement(query);
  63. psmt.setString(1,carmod);
  64. ResultSet rs = psmt.executeQuery();
  65. while(rs.next()){
  66. %><option value ="<%=rs.getInt("ProductID")%>" <%
  67. if(request.getParameter("carmodel") !=null){
  68. if(rs.getInt("ProductID")==Integer.parseInt(request.getParameter("carmodel")))
  69. {
  70. out.print("Selected");
  71. }
  72. }
  73. %>><%=rs.getString("carmodel")%></option><%
  74. }
  75. }catch(Exception e){
  76. e.printStackTrace();
  77. }%>
  78. </select>
  79.  
  80. </p>
  81.  
  82. <table class="table table-bordered table-striped" style="width: 90%">
  83. <tr>
  84. <th>CarID</th>
  85. <th>Image</th>
  86. <th>Car Make</th>
  87. <th>Car Model</th>
  88. <th>Car Description</th>
  89. <th>Start Date</th>
  90. <th>End Date</th>
  91.  
  92. </tr>
  93.  
  94. <%
  95.  
  96. try{
  97. Class.forName("com.mysql.jdbc.Driver").newInstance();
  98. Connection con= DriverManager.getConnection("jdbc:mysql://localhost/auction","root","cenk");
  99. String Query3 ="SELECT ProductID,images,cartype,carmodel,cardetails,startDate,enddate FROM `auction_items` WHERE ProductID=?";
  100. PreparedStatement psmt=con.prepareStatement(Query3);
  101. psmt.setString(1,request.getParameter("carmodel"));
  102. ResultSet rs = psmt.executeQuery();
  103.  
  104. while(rs.next()){
  105. %>
  106. <tr>
  107. <td><%=rs.getInt("ProductID")%></td>
  108. <td><%=rs.getString("images")%></td>
  109. <td><%=rs.getString("cartype")%></td>
  110. <td><%=rs.getString("carmodel")%></td>
  111. <td><%=rs.getString("cardetails")%></td>
  112. <td><%=rs.getString("startDate")%></td>
  113. <td><%=rs.getString("enddate")%></td>
  114. </tr>
  115. <%
  116.  
  117. }
  118. }
  119. catch(Exception e){
  120. e.printStackTrace();
  121. }
  122.  
  123.  
  124. %>
  125.  
  126.  
  127. </table>
  128.  
  129. </center>
  130. </form>
  131.  
  132. </body>
  133. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement