• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding code to return an ArrayList of objects

 
Derek Harper
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20729
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic