aspose file tools*
The moose likes Beginning Java and the fly likes How to store resultset  field value into array? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to store resultset  field value into array?" Watch "How to store resultset  field value into array?" New topic
Author

How to store resultset field value into array?

Mindy Wu
Ranch Hand

Joined: Jan 12, 2001
Posts: 121
We can use getxxx to get the resultset's individual feild value, how can we use an array object to store a record (row) value?
For example: resultset has 5 columns/fields and they have different data type. Can we do this:
while (rs.next())
Object[][][][][]= { {rs.getObject(1)}, {rs.getObject(2)},...,{rs.getObject(50} }
I think my syntax is wrong, can anyone give me some helps?
Thanks!
Mindy
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Mindy,
Think about using vectors.

Once you have the vector filled you can use the method toArray to get an array of objects if you want (I really don't advise it though).
Regards,
Manfred.
Mindy Wu
Ranch Hand

Joined: Jan 12, 2001
Posts: 121
Thanks Manfred,
Can you tell me why shouldn't i use vector? Do you have any alternative methods to do that? After I copied the vector into an array, how can i access each element?
Vector v = new Vector(numberOfRows);
while( rsParameter.next() )
{
v1 = new Vector();
for( int i = 0; i < 5; ++i )
{
v1.addElement( rs.getObject( 1 ) );
}
v.addElement( v1 );
}
arrayPars = new String[v.size()];
v.copyInto(arrayPars);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to store resultset field value into array?