0% found this document useful (0 votes)
10 views1 page

Displaybook

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)
10 views1 page

Displaybook

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>E-Book Store - Display Book</title>
</head>
<body>
<%@ page import="java.sql.*" %>
<%
Class.forName("com.mysql.jdbc.Driver");
String URL = "jdbc:mysql://localhost/bookstorejsp";
String user = "root";
String pass = "";
Connection conn = DriverManager.getConnection(URL, user, pass);
Statement stmt = conn.createStatement();

String sql = "SELECT * FROM books";


ResultSet rs = stmt.executeQuery(sql);
// Display the records in an HTML table
if (rs.next()) {
%>
<h2 align="center">Book Records</h2>
<table border="2" align="center" cellpadding="10" width="30%">
<tr>
<th>Book ID</th>
<th>Title</th>
<th>Price</th>
</tr>
<% while (rs.next()) { %>
<tr>
<td><%= rs.getInt("id") %></td>
<td><%= rs.getString("title") %></td>
<td>Rs. <%= rs.getInt("price") %></td>
</tr>
<% } %>
</table>
<%
} else {
out.println("No book records found.");
}

rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

You might also like