Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%--
- Document : dbconnect
- Created on : 02-Sep-2018, 13:53:37
- Author : Elsemelawy
- --%>
- <% Class.forName("con.mysql.jdbc.Driver");%>
- <%@page import="java.sql.*" %>
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>DB Connect</title>
- </head>
- <body>
- <h1>select data from DB </h1>
- <%!
- public class Actor
- {
- String url ="jdbc:mysql://localhost:3306/mysql ";
- String username = "root";
- String password ="root";
- Connection connection = null;
- PreparedStatement selectActor= null;
- ResultSet resultset= null;
- public Actor(){
- try
- {
- connection =DriverManager.getConnection(url,username,password);
- selectActor=connection.prepareStatement("select actor_id, first_name,Last_name from actor ");
- }
- catch (SQLException e){
- e.printStackTrace();
- }
- }
- public ResultSet getactor(){
- try{
- resultset = selectActor.executeQuery();
- }
- catch(SQLException e)
- {
- e.printStackTrace();
- }
- return resultset;
- }
- }
- %>
- <%
- Actor actor= new Actor();
- ResultSet actors = actor.getactor();
- %>
- <table border="1">
- <tbody>
- <tr>
- <td>actor id</td>
- <td>first name</td>
- <td>last name</td>
- </tr>
- <% while (actors.next()) { %>
- <tr>
- <td><%=actors.getInt("actor_id")%></td>
- <td><%=actors.getString("first_name")%></td>
- <td><%=actors.getString("last_name")%></td>
- </tr>
- <%}%>
- </tbody>
- </table>
- </body>
- </html>
Add Comment
Please, Sign In to add comment