File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Soft Skills this week in the Jobs Discussion 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: 18986
    
    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.
  •  
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Adding code to return an ArrayList of objects