Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@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>Selecting Data from a DB</title>
- </head>
- <body>
- <h1>Selecting Data From a DB</h1>
- <%!
- public class Actor{
- String URL = "jdbc:mysql://localhost:3306/crow";
- String USERNAME = "root";
- String password = "Knight69!";
- Connection connection = null;
- PreparedStatement selectActors = null;
- ResultSet resultSet = null;
- public Actor(){
- try {
- connection = DriverManager.getConnection(URL, USERNAME, password);
- selectActors = connection.prepareStatement(
- "Select authorNum, authorFirst, authorLast FROM author");
- }catch (SQLException e){
- e.printStackTrace();
- }
- }
- public ResultSet getActors(){
- try{
- resultSet = selectActors.executeQuery();
- }catch (SQLException e){
- e.printStackTrace();
- }
- return resultSet;
- }
- }
- %>
- <%
- Actor actor = new Actor();
- ResultSet actors = actor.getActors();
- %>
- <table border="1">
- <tbody>
- <tr>
- <td>Author Num</td>
- <td>Author First</td>
- <td>Author Last</td>
- </tr>
- <% while (actors.next()) { %>
- <tr>
- <td><%= out.println(actors.getInt("authorNum"))%></td>
- <td><%= out.println(actors.getString("authorFirst"))%><</td>
- <td><%= out.println(actors.getString("authorLast"))%></td>
- </tr>
- </tbody>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement