Advertisement
Guest User

Untitled

a guest
Apr 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. <%@page import="java.sql.*"%>
  2. <% Class.forName("com.mysql.jdbc.Driver"); %>
  3. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  8. <title>Selecting Data from a DB</title>
  9. </head>
  10. <body>
  11. <h1>Selecting Data From a DB</h1>
  12. <%!
  13. public class Actor{
  14. String URL = "jdbc:mysql://localhost:3306/crow";
  15. String USERNAME = "root";
  16. String password = "Knight69!";
  17.  
  18. Connection connection = null;
  19. PreparedStatement selectActors = null;
  20. ResultSet resultSet = null;
  21.  
  22. public Actor(){
  23.  
  24. try {
  25. connection = DriverManager.getConnection(URL, USERNAME, password);
  26.  
  27. selectActors = connection.prepareStatement(
  28. "Select authorNum, authorFirst, authorLast FROM author");
  29.  
  30. }catch (SQLException e){
  31. e.printStackTrace();
  32. }
  33. }
  34. public ResultSet getActors(){
  35. try{
  36. resultSet = selectActors.executeQuery();
  37. }catch (SQLException e){
  38. e.printStackTrace();
  39. }
  40.  
  41. return resultSet;
  42. }
  43. }
  44. %>
  45. <%
  46. Actor actor = new Actor();
  47. ResultSet actors = actor.getActors();
  48. %>
  49. <table border="1">
  50. <tbody>
  51. <tr>
  52. <td>Author Num</td>
  53. <td>Author First</td>
  54. <td>Author Last</td>
  55. </tr>
  56. <% while (actors.next()) { %>
  57. <tr>
  58. <td><%= out.println(actors.getInt("authorNum"))%></td>
  59. <td><%= out.println(actors.getString("authorFirst"))%><</td>
  60. <td><%= out.println(actors.getString("authorLast"))%></td>
  61. </tr>
  62. </tbody>
  63. </table>
  64.  
  65. </body>
  66. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement