• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

HELP - Multidimensional array question

 
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to populate a multidimensional array from a resultset. Here is what I've attempted thus far:

conn = transaction.SQLConn();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sqlstmt);
Values[] fvalues = new Values[response.getRows().length];
String fname = fvalues[0].getFieldValue().getName();
String fvalue = fvalues[1].getFieldValue().getValue();
for (int i = 0; i < fvalues.length; i++){
for(int j=0;j<fvalues[i].length;j++){
fvalues[i][fname] = new Integer((i+1)*(j+1));
}
}

Any help would be appreciated. Arrays are seriously confusing me to no end.

Thanks.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, for starters, you don't have a multidimensional array. You have a single. Next..

Values[] fvalues = new Values[response.getRows().length];
String fname = fvalues[0].getFieldValue().getName();
String fvalue = fvalues[1].getFieldValue().getValue();

You haven't given the elements of fvalues any data yet. It is merely an empty array (albeit with default values) the size of your rows.

And then the whole forloop you've got going doesn't make sense because, like I said, you didn't create a multidimensional array. So you are trying to do [][] operations when you only have [] defined. Make sense?

I except you are getting errors along side these problems but you failed to post those.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I am working on a webservice whereby I am trying to populate an array from where I can send back a response that looks like the XML below:

The XML will look like the following for each row:

<rows>
<row>
<field value>
<name>ReqNumber</name>
<value>12345</value>
</field value>
<field value>
<name>ReqStatus</name>
<value>A</value>
</field value>
</row>
</rows>

My apologies for what is probably a stupid question but therein lies my problem with arrays.

Again, any help or direction is appreciated. Thanks.
 
Sheriff
Posts: 9099
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I only see one array declared, fvalues, and it is not a multidimensional array.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!