Advertisement
Guest User

PART A JSP

a guest
Apr 11th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <%@ page import="java.sql.*" %>
  2. <html>
  3. <head><title>JSP PART A - LAB 9</title></head>
  4. <body>
  5. <p>Displays course information for course numbers less than 100</p>
  6. <%
  7. out.println("Program: part1.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.  
  21. String stringQuery = ("SELECT description, cost, prerequisite, created_by, created_date, modified_by, modified_date FROM course WHERE course_no <100");
  22.  
  23. PreparedStatement preState = conn.prepareStatement(stringQuery);
  24.  
  25. ResultSet rset = preState.executeQuery();
  26.  
  27. out.println("Description, Cost, Prerequsite<br>");
  28. while(rset.next())
  29. out.println(rset.getString("description") + ", " + rset.getString("cost") + " ," + rset.getString("prerequisite") + "<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