wood burning stoves 2.0*
The moose likes JDBC and the fly likes Can i filter Result set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Can i filter Result set" Watch "Can i filter Result set" New topic
Author

Can i filter Result set

surendar prabu
Ranch Hand

Joined: Jul 24, 2006
Posts: 102
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.


SCJP 1.4
Rajah Nagur
Ranch Hand

Joined: Nov 06, 2002
Posts: 239
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.


You can't wake a person who is <b><i>pretending</i></b> to be asleep.<br />Like what <b>"it"</b> does not like - <i> Gurdjieff </i>
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
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

Joined: Jul 24, 2006
Posts: 102
Thank you Rajah.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can i filter Result set