Advertisement
Guest User

Untitled

a guest
Oct 26th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 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 cartype= null;
  25. int b=0;
  26.  
  27. try{
  28. String Query="Select * FROM auction_items GROUP BY cartype";
  29. Class.forName("com.mysql.jdbc.Driver").newInstance();
  30. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/auction","root","cenk");
  31. Statement st= conn.createStatement();
  32. ResultSet rs= st.executeQuery(Query);
  33. while(rs.next()){
  34. %><option value ="<%=rs.getInt("ProductID")%>"
  35.  
  36. <%
  37. if(request.getParameter("cartype") !=null){
  38. if(rs.getInt("ProductID")==Integer.parseInt(request.getParameter("cartype")))
  39. {
  40. out.print("Selected");
  41. cartype=rs.getString("cartype");
  42. b=1;
  43. }
  44. }
  45.  
  46.  
  47.  
  48. %>><%=rs.getString("cartype")%></option><%
  49.  
  50. }
  51.  
  52. }catch(Exception e){
  53. e.printStackTrace();
  54. }
  55.  
  56. %>
  57. </select>
  58. </p>
  59. Car model:
  60. <select name="carmodel" id="carmodel" onchange="this.form.submit();">
  61. <option value="0">Select Car Model</option>
  62. <%
  63. String query = null;
  64. String carmod = null;
  65. try{
  66. query="Select * FROM auction_items WHERE cartype=? Group by carmodel";
  67. Class.forName("com.mysql.jdbc.Driver").newInstance();
  68. Connection con= DriverManager.getConnection("jdbc:mysql://localhost/auction","root","cenk");
  69. PreparedStatement psmt=con.prepareStatement(query);
  70. psmt.setString(1,cartype);
  71. ResultSet rs = psmt.executeQuery();
  72. while(rs.next()){
  73. %><option value ="<%=rs.getInt("ProductID")%>" <%
  74. if(request.getParameter("carmodel") !=null){
  75. if(rs.getInt("ProductID")==Integer.parseInt(request.getParameter("carmodel")))
  76. {
  77. out.print("Selected");
  78. carmod= rs.getString("carmodel");
  79. b=2;
  80. }
  81. }
  82. %>><%=rs.getString("carmodel")%></option><%
  83. }
  84. }catch(Exception e){
  85. e.printStackTrace();
  86. }%>
  87. </select>
  88.  
  89. </p>
  90.  
  91. <table class="table table-bordered table-striped" style="width: 90%">
  92. <tr>
  93. <th>Car</th>
  94. <th>Image</th>
  95. <th>Car Make</th>
  96. <th>Car Model</th>
  97. <th>Car Description</th>
  98. <th>Start Date</th>
  99. <th>End Date</th>
  100.  
  101. </tr>
  102.  
  103. <%
  104.  
  105. try{
  106. Class.forName("com.mysql.jdbc.Driver").newInstance();
  107. Connection con= DriverManager.getConnection("jdbc:mysql://localhost/auction","root","cenk");
  108. String Query3 = null;
  109.  
  110. if(b==1)
  111. Query3 = "SELECT ProductID,images,cartype,carmodel,cardetails,startDate,enddate FROM auction_items WHERE cartype=?";
  112. if(b==2)
  113. Query3 = "SELECT ProductID,images,cartype,carmodel,cardetails,startDate,enddate FROM auction_items WHERE carmodel=?";
  114.  
  115. PreparedStatement psmt=con.prepareStatement(Query3);
  116. if(b==1)
  117. psmt.setString(1,cartype);
  118. if(b==2)
  119. psmt.setString(1,carmod);
  120.  
  121. ResultSet rs = psmt.executeQuery();
  122.  
  123.  
  124. while(rs.next()){
  125. %>
  126. <tr>
  127. <td><input type="radio" name="pid" value ="<%=rs.getInt("ProductID")%>"</input></td>
  128. <td><a href="bidding.jsp"><%=rs.getString("images")%></a></td>
  129. <td><a href="bidding.jsp"><%=rs.getString("cartype")%></a></td>
  130. <td><a href="bidding.jsp"><%=rs.getString("carmodel")%></a></td>
  131. <td><a href="bidding.jsp"><%=rs.getString("cardetails")%></a></td>
  132. <td><a href="bidding.jsp"><%=rs.getString("startDate")%></a></td>
  133. <td><a href="bidding.jsp"><%=rs.getString("enddate")%></a></td>
  134. </tr>
  135. <%
  136.  
  137. }
  138. }
  139. catch(Exception e){
  140. e.printStackTrace();
  141. }
  142.  
  143. %>
  144. </table>
  145.  
  146. </center>
  147. </form>
  148.  
  149. </body>
  150. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement