Guest User

Untitled

a guest
Sep 3rd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. <%--
  2. Document : dbconnect
  3. Created on : 02-Sep-2018, 13:53:37
  4. Author : Elsemelawy
  5. --%>
  6. <% Class.forName("con.mysql.jdbc.Driver");%>
  7. <%@page import="java.sql.*" %>
  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>DB Connect</title>
  14. </head>
  15. <body>
  16. <h1>select data from DB </h1>
  17. <%!
  18. public class Actor
  19. {
  20. String url ="jdbc:mysql://localhost:3306/mysql ";
  21. String username = "root";
  22. String password ="root";
  23. Connection connection = null;
  24. PreparedStatement selectActor= null;
  25. ResultSet resultset= null;
  26. public Actor(){
  27. try
  28. {
  29. connection =DriverManager.getConnection(url,username,password);
  30. selectActor=connection.prepareStatement("select actor_id, first_name,Last_name from actor ");
  31.  
  32. }
  33.  
  34. catch (SQLException e){
  35. e.printStackTrace();
  36.  
  37.  
  38. }
  39. }
  40.  
  41. public ResultSet getactor(){
  42. try{
  43. resultset = selectActor.executeQuery();
  44. }
  45. catch(SQLException e)
  46. {
  47. e.printStackTrace();
  48. }
  49. return resultset;
  50. }
  51.  
  52. }
  53. %>
  54. <%
  55. Actor actor= new Actor();
  56. ResultSet actors = actor.getactor();
  57.  
  58.  
  59. %>
  60. <table border="1">
  61.  
  62. <tbody>
  63. <tr>
  64. <td>actor id</td>
  65. <td>first name</td>
  66. <td>last name</td>
  67. </tr>
  68. <% while (actors.next()) { %>
  69. <tr>
  70. <td><%=actors.getInt("actor_id")%></td>
  71. <td><%=actors.getString("first_name")%></td>
  72. <td><%=actors.getString("last_name")%></td>
  73. </tr>
  74. <%}%>
  75. </tbody>
  76. </table>
  77.  
  78. </body>
  79. </html>
Add Comment
Please, Sign In to add comment