• Post Reply Bookmark Topic Watch Topic
  • New Topic

List in Java  RSS feed

 
John Joe
Ranch Hand
Posts: 443
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, I trying to understand how list works.
I have a table name ABC. I use this method to add all the data into list.
Code
But if I want to write like this, what does this mean and what is the logic I can write ?
Code

The first one, it consider  as list, how about the second ?
Thanks.

 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Joe wrote:.  . . I trying to understand how list works. . . .
Why are you using a StringBuilder when you could write the String as a literal?
Why not simply print that List and then you can see what it contains.

What do you get from the query as a return type? Where is the getResultList method from?
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing this is a JPA app and that em is an EntityManager.

If you are expecting only a single result back, then use getSingleResult on the Query object, and not getResultList.
 
John Joe
Ranch Hand
Posts: 443
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:What do you get from the query as a return type? Where is the getResultList method from?
It is JPA query
 
John Joe
Ranch Hand
Posts: 443
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:I'm guessing this is a JPA app and that em is an EntityManager.
If you are expecting only a single result back, then use getSingleResult on the Query object, and not getResultList.
Yes, that's what I'm looking. Thanks
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!