This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Adding code to return an ArrayList of objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Adding code to return an ArrayList of objects" Watch "Adding code to return an ArrayList of objects" New topic
Author

Adding code to return an ArrayList of objects

Derek Harper
Greenhorn

Joined: Aug 02, 2006
Posts: 25
Greetings friends,

I am working on an exercise in "Murach's Servlets & JSP" where i am trying to add code to a method in order to return an arrayList of objects. Here is the code below:




In the latter part of the code, i've added code to the "selectUsers" method to return an arrayList of User objects that corresponds with the rows in the User table. When I run the program, it compiles and brings up the page, and when I click on the link to display users, it only shows the table heading.

Please advise as to what I am doing wrong. Is something wrong with the arrayList?

If you need any additional information from me, please let me know. Thanks in advance.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

The first thing I can see which is wrong is that, although you declare the method to return an ArrayList of User objects, you're putting three Strings into the ArrayList and returning that. Based on the name of the method, I would expect to see some JDBC code that did this:
  • Go through the whole User table.
  • Create a User object from each row of the table and add it to an ArrayList.
  • Return that ArrayList.
  •  
    jQuery in Action, 2nd edition
     
    subject: Adding code to return an ArrayList of objects
     
    Similar Threads
    autoincrement invoice
    how to convert to statements to an array
    Timestamp assistance
    LAST_INSERT_ID() with threads
    Validation/DB query question