Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%--
- Document : index
- Created on : May 16, 2018, 11:18:01 PM
- Author : Maneesh Reddy
- --%>
- <%@page import="java.sql.*" %>
- <% Class.forName("com.mysql.jdbc.Driver"); %>
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>JSP Page</title>
- </head>
- <body>
- <h1>Gokaraju Rangaraju Online Shopping</h1>
- <%!
- public class Catalog{
- String URL="jdbc:mysql//localhost3306/sakila";
- String USERNAME = "root";
- String PASSWORD = "Arrow@786";
- Connection conn = null;
- Statement stmt = null;
- ResultSet resultset = null;
- public Catalog(){
- //establish the connection
- try{
- conn = DriverManager.getConnection(URL,USERNAME,PASSWORD);
- stmt = conn.createStatement();
- }
- catch(SQLException e){
- e.printStackTrace();
- }
- }
- public ResultSet getData(){
- try{
- resultset = stmt.executeQuery("select * from catalog");
- }
- catch(SQLException e){
- e.printStackTrace();
- }
- return resultset;
- }
- }
- %>
- <%
- Catalog catalog = new Catalog();
- ResultSet rs = catalog.getData();
- String[] bookname = new String[15];
- int[] price = new int[15];
- int[] quantity = new int[15];
- int[] amount = new int[15];
- int count=0;
- //loop through all the results and store them
- for(int i=0;rs.next();++i){
- count += 1;
- bookname[i] = rs.getString(1);
- price[i] = rs.getInt(2);
- quantity[i] = rs.getInt(3);
- amount[i] = rs.getInt(4);
- }
- if(count!=0){
- %>
- <table border="1">
- //Add headings
- <tr>
- <th>BookName</th>
- <th>Price</th>
- <th>Quantity</th>
- <th>Amount</th>
- </tr>
- <% for(int i=0;i<count;++i){
- %>
- <tr>
- <td><%= bookname[i] %></td>
- <td><%= price[i] %></td>
- <td><%= quantity[i]%></td>
- <td><%= amount[i] %></td>
- </tr>
- <%
- }
- %>
- </table>
- <%
- }
- %>
- </body>
- </html>
Add Comment
Please, Sign In to add comment