Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Put Resultset into Array or Vector 2

Status
Not open for further replies.

JSUAlumni

Programmer
Mar 29, 2001
21
US
I need some help in putting a result set into an array. First, I have a query that returns time. Assuming it returns 4 values, how would I go about reading the values into an array? (If I would be better off to use a vector I would appreciate that help too.) Also, let's say the query returned time, person, and event such as:
Time1.25 PersonX EventA
Time2.25 PersonY EventB
What can I use so that I could loop through and be able to see time '1.25' ,person 'X', and event 'A' and so on?
Example: If the first row were say row[1] I could say something to the effect of:
if (row[1].time < row [2].time) and (row[2].person != EventC)
do something
I hope I'm making myself somewhat clear..... Please help if you can.
 
Is this helpful? If you have more questions... just holla!

Code:
public class Inner {
  public double time;
  public String person;
  public String event;
}

Vector container = new Vector();
// you can do this so you can start with an index of 1
container.addElement(null);

ResultSet rs = your resultset...

while(rs.next()) {
  Inner inner = new Inner();
  inner.time   = rs.getDouble(1);
  inner.person = rs.getString(2);
  inner.event  = rs.getString(3);
  container.addElement(inner);
}

if(container.elementAt(1).time < container.elementAt(2).time
  && container.elementAt(2).person != EventC) {
  //do something...
}
I hope this helped! ;-)
- Casey Winans
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top