Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jump to a specific record of a Resultset

 
vishal shah
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
vishal shah
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic