Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 1.40 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  2. pageEncoding="ISO-8859-1"%>
  3. <%@ page import="java.sql.*" %>
  4.  
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  6. <html>
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  9. <title>Insert title here</title>
  10. </head>
  11. <body>
  12.  
  13. <%
  14. // Step1: Load JDBC Driver
  15. Class.forName("com.mysql.jdbc.Driver");
  16. // Step 2: Define Connection URL
  17. String connURL ="jdbc:mysql://localhost/jspg?user=root&password=root";
  18. // Step 3: Establish connection to URL
  19. Connection conn =   DriverManager.getConnection(connURL);
  20. // Step 4: Create Statement object
  21. Statement stmt = conn.createStatement();
  22. // Step 5: Execute SQL Command
  23. String sqlStr = "SELECT * FROM student";        
  24. ResultSet rs = stmt.executeQuery(sqlStr);
  25.  out.println("<table border ='1'>");
  26.  out.println("<tr>");
  27.  out.println("<td>ID</td>");
  28.  out.println("<td>Name</td>");
  29.  out.println("<td>Age</td>");
  30.  
  31.  while (rs.next()){
  32.          //out.println("<tr>");
  33.          int id = rs.getInt("id");
  34.          String name = rs.getString("name");
  35.          int age = rs.getInt("age");
  36.          out.println("<td> " + id + "</td>");
  37.          out.println("<td> " + name + "</td>");
  38.          out.println("<td> " + age + "</td>");
  39.  }
  40.  
  41. out.println("</table>");
  42. /*
  43. String simpleProc = "{call samplecall ('nic')}"; //your procedure name
  44. */
  45.  
  46. %>
  47.  
  48.  
  49. </body>
  50. </html>