
Untitled
By: a guest on
May 1st, 2012 | syntax:
None | size: 1.40 KB | hits: 20 | expires: Never
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
// Step1: Load JDBC Driver
Class.forName("com.mysql.jdbc.Driver");
// Step 2: Define Connection URL
String connURL ="jdbc:mysql://localhost/jspg?user=root&password=root";
// Step 3: Establish connection to URL
Connection conn = DriverManager.getConnection(connURL);
// Step 4: Create Statement object
Statement stmt = conn.createStatement();
// Step 5: Execute SQL Command
String sqlStr = "SELECT * FROM student";
ResultSet rs = stmt.executeQuery(sqlStr);
out.println("<table border ='1'>");
out.println("<tr>");
out.println("<td>ID</td>");
out.println("<td>Name</td>");
out.println("<td>Age</td>");
while (rs.next()){
//out.println("<tr>");
int id = rs.getInt("id");
String name = rs.getString("name");
int age = rs.getInt("age");
out.println("<td> " + id + "</td>");
out.println("<td> " + name + "</td>");
out.println("<td> " + age + "</td>");
}
out.println("</table>");
/*
String simpleProc = "{call samplecall ('nic')}"; //your procedure name
*/
%>
</body>
</html>