Guest User

jsp

a guest
Aug 10th, 2018
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. <%@page import="java.sql.DriverManager"%>
  2. <%@page import="java.io.PrintWriter"%>
  3. <%@page import="java.sql.ResultSet"%>
  4. <%@page import="java.sql.Connection"%>
  5. <%@page import="java.sql.DatabaseMetaData"%>
  6. <%@page import="java.sql.PreparedStatement"%>
  7. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  8. pageEncoding="ISO-8859-1"%>
  9. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  10. <html>
  11. <head>
  12. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  13. <title>Insert title here</title>
  14. </head>
  15. <body>
  16. <form method="post" action="AddQueWithDept.jsp">
  17. <CENTER>
  18.  
  19. <%! String dat; %>
  20.  
  21. Department: <select name="dep">
  22. <%
  23. Class.forName("com.mysql.jdbc.Driver");
  24. Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
  25. PreparedStatement ps=con.prepareStatement("select * from deptTopics");
  26. ResultSet x=ps.executeQuery();
  27. while(x.next())
  28. {
  29. dat = x.getString("DepartmentName");
  30. %>
  31.  
  32. <option value="<%=dat%>"> <%=dat%> </option>
  33. <%
  34. }
  35. %>
  36. </select><br>
  37.  
  38.  
  39.  
  40. Topic Name <select name="TopicName">
  41.  
  42. <%
  43. PreparedStatement ps1=con.prepareStatement("select * from deptTopics where DepartmentName = '"+dat+"'");
  44. ResultSet xy=ps1.executeQuery();
  45. while(xy.next())
  46. {
  47. String datx = xy.getString("TopicName");
  48. %>
  49.  
  50. <option value="<%=datx%>"> <%=datx%> </option>
  51. <%
  52. }
  53. %>
  54.  
  55.  
  56.  
  57. </select>
  58.  
  59.  
  60. Question<input type="text" name="Question"><br>
  61. Answer<input type="text" name="Answer">
  62.  
  63.  
  64. <input type="submit" value="submit">
  65.  
  66.  
  67.  
  68. </CENTER>
  69. </form>
  70. </body>
  71. </html>
Add Comment
Please, Sign In to add comment