JSP Java Tutorial

<%@ page  import="java.sql.*" %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); %>

    
        Joining Tables
    
    
        

Joining Tables


        <% 
            Connection connection = DriverManager.getConnection(
                "jdbc:odbc:data", "YourName", "password");
            Statement statement = connection.createStatement();
            String query = "SELECT authors.au_fname, authors.au_lname, titleauthor.title_id " +
              "FROM authors INNER JOIN titleauthor ON authors.au_id = titleauthor.au_id";
            ResultSet resultset = 
                statement.executeQuery(query) ; 
        %>
        
            
                First Name
                Last Name
                Book ID
            
            <% while(resultset.next()){ %>
            
                 <%= resultset.getString(1) %>
                 <%= resultset.getString(2) %>
                 <%= resultset.getString(3) %>
            
            <% } %>