Solved

Browsing the resultSet

Posted on 1998-11-14
1
304 Views
Last Modified: 2010-03-30
I know that I can use method next()to browse forward the resultSet.  However, I want to know how can I browse backward in the resultSet. I use Java 1.1, so I can't use the new method suggested in Java 1.2. Can anyone tell me how to implement the backward browsing and give me the implemention?
0
Comment
Question by:q1w2
1 Comment
 
LVL 16

Accepted Solution

by:
heyhey_ earned 50 total points
ID: 1227426
you can "browse" the result set only forward.
quote
" A ResultSet provides access to a table of data generated by executing a Statement. The table rows are retrieved in sequence. Within a row its column values can be accessed in any order. "

if you need to access some rows more then once, you'll have to make a copy (cache them)

Vector rows = new Vector();
Vector curRow;
Object elem;

while (resultSet.next())
{
  curRow = new Vector();
  elem = resulSet.getObject(1);
  curRow.addElement(elem);
  elem = resulSet.getObject(2);
  curRow.addElement(elem);
  elem = resulSet.getObject(3);
  curRow.addElement(elem);
// ....
// now curRow has a copy of all objects from the current row of the result set
  rows.addElement(CurRow);
}


now you have all the information from the resultSet cached in the rows vector
if you need field 2 of the third row, you use

Object o - (Vector)(rows.elementAt(3)).elementAt(2);

hope this helps
  heyhey
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now