File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to store resultset field value into array?

 
Mindy Wu
Ranch Hand
Posts: 121
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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);
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic