0% found this document useful (0 votes)
7 views

Display Using HTML Table

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Display Using HTML Table

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Display Records</title>
</head>
<body>
<%-- Importing SQL --%>
<%@ page import = "java.sql.*" %>
<center><h2>Displaying Student Records</h2></center>
<%-- Working with JDBC --%>
<%
try {
Class.forName("com.mysql.jdbc.Driver");
String url ="jdbc:mysql://localhost:3306/studentdbwithjsp" ;
String username="root";
String password="";
Connection conn =
DriverManager.getConnection(url,username,password);
Statement stmt = conn.createStatement();
String Query = "SELECT * FROM student";

ResultSet rs = stmt.executeQuery(Query);

%>
<table border="2" align="center" cellpadding="10" width="30%">
<tr> <th> ID </th> <th> Name </th> <th> Age </th> </tr>
<% while(rs.next()) { %>
<tr>
<td> <%= rs.getInt(1) %> </td>
<td> <%= rs.getString(2) %> </td>
<td> <%= rs.getInt(3) %> </td>
</tr>
<% }
conn.close();
}
catch (Exception e) {
out.print("Error: "+e);
}
%>
</body>
</html>

You might also like