my dog learned polymorphism*
The moose likes Beginning Java and the fly likes HELP - Multidimensional array question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HELP - Multidimensional array question" Watch "HELP - Multidimensional array question" New topic
Author

HELP - Multidimensional array question

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

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

Joined: Jul 22, 2000
Posts: 9044
    
  10

I only see one array declared, fvalues, and it is not a multidimensional array.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
 
subject: HELP - Multidimensional array question