This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can i filter Result set

 
surendar prabu
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a table login it has three fields username,password and address(all varchars). I want select all data from the table(select * from login) and store it in a resultset, then i want to get the data from the resultset as i need.like select only the usernames, select all fields for the given username etc; Is there any way that i can retreive data by filtering the resultset.

simply, i dont want to write many queries to retrieve data from a single table.
 
Rajah Nagur
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not good practice from performance perspective to hold on to a ResultSet. ResultSet opens a cursor to the database.

To address your usecase, you can get the results from the ResultSet and populate an User object (value object / entity object) and maintain these objects in any collection (Map/Set). Close the ResultSet.

You can do many utility operations like getting only the keys, getting particular set of values for any key etc on this collection object.
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rajah Nagur:
It is not good practice from performance perspective to hold on to a ResultSet. ResultSet opens a cursor to the database.


True. Just as bad, it also requires you to keep the connection open and allocated for a long time. Database connections are scarce resources too.
 
surendar prabu
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Rajah.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic