Advertisement
Guest User

PART B JSP

a guest
Apr 11th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <%@ page import="java.sql.*" %>
  2. <html>
  3. <head><title>JSP PART B - LAB 9</title></head>
  4. <body>
  5. <p>an instructor last name & returnt he courses they teach</p>
  6. <%
  7. out.println("Program: partb.jsp <br>");
  8. try {
  9. Class.forName("oracle.jdbc.OracleConnection");
  10. out.println("Driver loaded <br>");
  11. }
  12. catch (ClassNotFoundException e) {
  13. out.println("Could not load the driver <br>");
  14. }
  15. String user = "N01125338";
  16. String passwd = "oracle";
  17. try {
  18. Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@munro.humber.ca:1521:msit", user, passwd);
  19. out.println("Database connected <br><br>");
  20. String name = request.getParameter("value1");
  21. String stringQuery = ("SELECT i.instructor_id, i.last_name, s.course_no,c.description FROM instructor i, section s, course c WHERE i.instructor_id = s.instructor_id AND s.course_no = c.course_no AND i.last_name = ?");
  22.  
  23. PreparedStatement preState = conn.prepareStatement(stringQuery);
  24. preState.setString(1, name);
  25. ResultSet rset = preState.executeQuery();
  26.  
  27. out.println("Course Number, Course Name <br>");
  28. while(rset.next())
  29. out.println(rset.getString("course_no") + ", " + rset.getString("description") + "<br>" );
  30.  
  31. preState.close();
  32. }
  33. catch (SQLException e) {
  34. out.println("Could not make Oracle connection");
  35. }
  36. %>
  37. </body>
  38. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement