This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes JDBC and the fly likes Jump to a specific record of a Resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Jump to a specific record of a Resultset" Watch "Jump to a specific record of a Resultset" New topic
Author

Jump to a specific record of a Resultset

vishal shah
Greenhorn

Joined: Feb 25, 2008
Posts: 3
Hi,

Is there any method through which we can jump to a specific record in a java.sql.Resultset (e.g. where the field name matches 'Vishal')?

Thanks,
Vishal
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26489
    
  78

Vish,
Welcome to JavaRanch!

Why not do a query specifically for the records you are interested in?

In other words "select * from table where field_name = 'Vishal'" rather than "select * from table". This will cut down on the amount of work the database has to do. And if you aren't using the data, there is no reason to return it to the Java layer.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
vishal shah
Greenhorn

Joined: Feb 25, 2008
Posts: 3
Hi Jeanne,

Thanks for your reply. The reason I am doing it is I have a database containing records of say, 1000 agents. Every month I recieve a new file containing updated counts for the agent. In this case I have to check if I have the agent already in my database or not. If the record does not exist, then I have to insert a record with the new values, else I have to update the existing record by adding the new values to the existing value. If there is no way of filtering a recordset of 1000 agents, then I will have to execute the select and update or insert query for each agent 1000 times. And also, this agent count could increase to 10000 in future!

I was thinking that I could create a recordset with all the existing records and then use the Resultset.updateRow() or Resultset.insertRow() method to update or insert which ever row I want. But the only problem is how do I get to that specific record without looping through the resultset.

Thanks,
Vishal
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26489
    
  78

Vishal,
I would approach it the other way: go through the resultset in the order it is returned and add/update for that record as needed.

This approach assumes you are getting updates for all the records. Otherwise, the select all query is inefficient in itself.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Assuming that your driver supports updatable ResultSets - have you checked? - it is possible that each row update will require a round-trip to the database. If so, then an updatable ResultSet may not suitable for updating thousands of rows.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Jump to a specific record of a Resultset
 
Similar Threads
drawing graph
Unlocking the entire database?
mysql simple doubt
Passed SCJP86%, Now SCWCD or IBM cert. Websphere
Cleared Part I with 77%