Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Displaying Array List from DB in table in JSP

843842Jun 2 2010 — edited Jun 7 2010
I am attempting to pull three data fields from my DB into an array list and pass the data from my servlet to a JSP page. I would like the data to be shown in a table and was wondering how to do so. This is what I have so far:

The original JSP page passes the employee's last name to a servlet as emp_lastname:
private void searchRecords(HttpServletResponse response,HttpServletRequest request){
    	
    	try{
    	ArrayList al = new ArrayList();
        ec.connect();
        ec.searchRecords(this.emp_lastname);
        response.sendRedirect("displayRecords.jsp");    		
    	}catch(Exception e){
    		System.out.println(e.toString());
    	}finally{
    	}
    }
The servlet sends emp_lastname to a class with the following method:
public ArrayList searchRecords(String emp_lastname){
    	ArrayList al = new ArrayList();
        PreparedStatement pstmt = null;
        ResultSet rs= null;
    	
    	
    	String sql = "select emp_id, emp_lastname, emp_firstnamename from employee where emp_lastname = ?";
        

        try{
	   	pstmt = connection.prepareStatement(sql);
	        pstmt.setEscapeProcessing(true);
	   		pstmt.setString(1,emp_lastname);
				rs = pstmt.executeQuery();
				while (rs.next()){
					String[] data = {rs.getString("emp_id"),rs.getString("emp_lastname"),rs.getString("emp_firstname")};
					al.add(data);				

				} //for
				rs.close();
				pstmt.close();           
        }catch(Exception es){
            System.out.println(es.toString());
        }finally{
            return al;
        }    	
    }
How would I go about getting the returned ArrayList to a displayRecords.jsp and display the data in a table with these column headers?
<table class="forms" cellpadding="0" border="0">  
   <tr class="def">
    <td>Employee ID</td>
    <td>First Name</td>
    <td>Last Name</td>
   </tr>  
   <tr>

   </tr>   	
   </table>
Thanks in advance for any assistance you can provide!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 5 2010
Added on Jun 2 2010
4 comments
7,809 views