Solved

Browsing the resultSet

Posted on 1998-11-14
1
293 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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 scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

707 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

20 Experts available now in Live!

Get 1:1 Help Now