Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Browsing the resultSet

Posted on 1998-11-14
1
Medium Priority
?
336 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 200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.
Suggested Courses

877 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