• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

list error

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I got a question regarding about list and iterator.

the problem is I got a list of type customer return from DataBase.
inside that list there are two elements customer_id and username.

how do I get that customer_id and username element out of the list?
even though I iterate it, it seem does not work.

Thanks in advance.

e.g in my DAO class I got the following


in my business class I got the following


 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.you have List of Customer

2.you have to get all the customers from the List. how do you do? you need an iterator
then you need to check any more Customer object is in list or not . how do you do this using hasNext() method of that iterator.

3. if any object is there you need to get one by one by using Iterator#next()

4. now you have a Customer object in your hand. you know how to get the properties for the object? using getters?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will have to look at the Customer class and see what methods it has for getting that data out. Does it have getID() and getUserName() for example? This is something we can't answer without having access to the Customer class.
 
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the error?

With the Iterator you can get the Customer object. Use getters methods to get the data.

I am not sure whether enhanced for loop work in place of Iterator? Give your valuable suggestions
 
tyte kyat
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes I do have getter and setter as follow

 
tyte kyat
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kunal, Steve and Seetharaman
I got the idea and solved it out now

the reason is I did not create an Object at first and the second is where I do in my DAOImpl class I have to modified it as follow.



instead of using



thanks you all
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also use criteria api. That's simple and you don't need to embed SQL query.
reply
    Bookmark Topic Watch Topic
  • New Topic