Guest User

CATALOGWEEK11

a guest
May 16th, 2018
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. <%--
  2. Document : index
  3. Created on : May 16, 2018, 11:18:01 PM
  4. Author : Maneesh Reddy
  5. --%>
  6. <%@page import="java.sql.*" %>
  7. <% Class.forName("com.mysql.jdbc.Driver"); %>
  8. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  9. <!DOCTYPE html>
  10. <html>
  11. <head>
  12. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  13. <title>JSP Page</title>
  14. </head>
  15. <body>
  16. <h1>Gokaraju Rangaraju Online Shopping</h1>
  17. <%!
  18. public class Catalog{
  19. String URL="jdbc:mysql//localhost3306/sakila";
  20. String USERNAME = "root";
  21. String PASSWORD = "Arrow@786";
  22.  
  23. Connection conn = null;
  24. Statement stmt = null;
  25. ResultSet resultset = null;
  26.  
  27. public Catalog(){
  28. //establish the connection
  29. try{
  30. conn = DriverManager.getConnection(URL,USERNAME,PASSWORD);
  31. stmt = conn.createStatement();
  32. }
  33. catch(SQLException e){
  34. e.printStackTrace();
  35. }
  36.  
  37. }
  38. public ResultSet getData(){
  39. try{
  40. resultset = stmt.executeQuery("select * from catalog");
  41. }
  42. catch(SQLException e){
  43. e.printStackTrace();
  44. }
  45. return resultset;
  46. }
  47. }
  48. %>
  49. <%
  50. Catalog catalog = new Catalog();
  51. ResultSet rs = catalog.getData();
  52. String[] bookname = new String[15];
  53. int[] price = new int[15];
  54. int[] quantity = new int[15];
  55. int[] amount = new int[15];
  56. int count=0;
  57. //loop through all the results and store them
  58. for(int i=0;rs.next();++i){
  59. count += 1;
  60. bookname[i] = rs.getString(1);
  61. price[i] = rs.getInt(2);
  62. quantity[i] = rs.getInt(3);
  63. amount[i] = rs.getInt(4);
  64.  
  65. }
  66.  
  67.  
  68. if(count!=0){
  69. %>
  70. <table border="1">
  71. //Add headings
  72. <tr>
  73. <th>BookName</th>
  74. <th>Price</th>
  75. <th>Quantity</th>
  76. <th>Amount</th>
  77. </tr>
  78. <% for(int i=0;i<count;++i){
  79. %>
  80. <tr>
  81. <td><%= bookname[i] %></td>
  82. <td><%= price[i] %></td>
  83. <td><%= quantity[i]%></td>
  84. <td><%= amount[i] %></td>
  85. </tr>
  86. <%
  87. }
  88. %>
  89. </table>
  90. <%
  91. }
  92. %>
  93.  
  94.  
  95. </body>
  96. </html>
Add Comment
Please, Sign In to add comment