How do I retrieve data from the database using jsp

advertisements

I want to retrieve information from my database.I got the input dynamically from user using html and through jsp i get the information from the database(Mysql).The following is the jsp code

       Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/indi", "root", "");

Statement statement = connection.createStatement();

         String id1 = request.getParameter("id");   

         ResultSet resultset = statement.executeQuery("select * from books where author = '" + id1 + "'") ; 

            if(!resultset.next()) {
                out.println("Sorry, could not find that publisher. ");
            } else {
        %>

        <TABLE BORDER="1">
            <TR>
               <TH>name</TH>
               <TH>author</TH>
               <TH>money</TH>
               <TH>company</TH>

           </TR>

           <TR>
               <TD> <%= resultset.getString(1) %> </TD>
               <TD> <%= resultset.getString(2) %> </TD>
               <TD> <%= resultset.getString(3) %> </TD>
               <TD> <%= resultset.getString(4) %> </TD>

           </TR>

       </TABLE>
       <BR>
       <%
           }
    }
       %>

I used author as a keyword to retrieve the data.Now i have 2 authors with the same name in my database but the above code fetches only one authors info i.e the first one and it leaves the other.Where should i modify in this code so that it will retrieve both the data


try to make a loop on resultset.

while(rs.next( )){
   %>
<TABLE BORDER="1">
        <TR>
           <TH>name</TH>
           <TH>author</TH>
           <TH>money</TH>
           <TH>company</TH>

       </TR>

       <TR>
           <TD> <%= resultset.getString(i) %> </TD>
           <TD> <%= resultset.getString(i+1) %> </TD>
           <TD> <%= resultset.getString(i+2) %> </TD>
           <TD> <%= resultset.getString(i+3) %> </TD>

       </TR>

   </TABLE>
   <BR>

 <% }  %>