This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to store resultset field value into array?

 
Mindy Wu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic