• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Jump to a specific record of a Resultset

 
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
 
author & internet detective
Posts: 39341
755
Eclipse IDE VI Editor Java
  • 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
Posts: 39341
755
Eclipse IDE VI Editor Java
  • 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.
 
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!