Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. <%@page import="java.sql.PreparedStatement"%>
  2. <%@page import="java.sql.SQLException"%>
  3. <%@page import="java.sql.ResultSet"%>
  4. <%@page import="java.sql.Statement"%>
  5. <%@page import="java.sql.Connection"%>
  6. <%@page import="java.sql.DriverManager"%>
  7. <html>
  8. <head>
  9. <title>Sample jsp</title>
  10. </head>
  11. <body>
  12. <%
  13. try {
  14. Class.forName("oracle.jdbc.OracleDriver");
  15. Connection conn = DriverManager.getConnection("jdbc:oracle:thin@localhost:1521:orcl", "system", "mono");
  16. PreparedStatement ps = conn.prepareStatement("SELECT * FROM person");
  17. // ps.setInt(1, qid);
  18. ResultSet rs = ps.executeQuery();
  19.  
  20. System.out.println("IDtNametPhone");
  21. while (rs.next()) {
  22. //int id = rs.getInt(1);
  23. String name = rs.getString(2);
  24. String phone = rs.getString(3);
  25. %><%= name%><%
  26. }
  27. } catch (Exception e) {
  28. e.printStackTrace();
  29. }
  30. %>
  31. </body>
  32. </html>
  33.  
  34. <%
  35. try
  36. {
  37. System.out.println("IDtNametPhone"); //Print in background
  38. out.print("<P>IDtNametPhone"); //Print to actual page
  39. while (rs.next())
  40. {
  41. //int id = rs.getInt(1);
  42. String name = rs.getString(2);
  43. String phone = rs.getString(3);
  44. out.print(name); //Print without closing/opening scriptlet
  45. }
  46. }
  47. catch (Exception e)
  48. {
  49. //Might not want to show the user the exact error in production though.
  50. out.print("Error: " + e.getMessage()); //print error to page
  51. e.printStackTrace(); //print error to log
  52. }
  53. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement