Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HELP - Multidimensional array question

 
Melinda Savoy
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.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 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.
 
Marilyn de Queiroz
Sheriff
Posts: 9059
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic