• 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

Can i filter Result set

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Rajah.
 
eat bricks! HA! And here's another one! And a tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic