How do I initialize an array, and how do I load data into it, and how do I retrieve it?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Masha_Reeves
Posted On:   Monday, November 12, 2001 01:00 PM

How do I initialize an array, and how do I load data into it, and how do I retrieve it? I'm experienced in JavaScript/HTML, but a newcomer to JSP. This sounds basic, but I can't find it anywhere. Please can someone help with this? String Query1="select * from tableone"; ResultSet SQLResult1 = SQLStatement.executeQuery(Query1); while(SQLResult1.next()){  fieldA = SQLResult1.getString("fieldA");  fieldB = SQLResult1.getString("fieldB");  fieldC = SQLResult1.getString("fieldC");  counter++; /* I need to load these value into an array here, I think -- how do I know the size    More>>

How do I initialize an array, and how do I load data into it, and how do I retrieve it?

I'm experienced in JavaScript/HTML, but a newcomer to JSP.

This sounds basic, but I can't find it anywhere.

Please can someone help with this?




String Query1="select * from tableone";

ResultSet SQLResult1 = SQLStatement.executeQuery(Query1);

while(SQLResult1.next()){

 fieldA = SQLResult1.getString("fieldA");

 fieldB = SQLResult1.getString("fieldB");

 fieldC = SQLResult1.getString("fieldC");

 counter++;

/* I need to load these value into an array here, I think -- how do I know the size to initialize it? and how do I write it?

*/

}




/* Now I want to iterate through the array to pull all the matches from another table

*/



for (i=0;i

 String Query2 ="select * from tabletwo where secondfieldA='"+myArray[i].fieldA+"'";

 ResultSet SQLResult2 = SQLStatement.executeQuery(Query2);

 while(SQLResult2.next()){

  fieldD = SQLResult2.getString("fieldD");

  fieldE = SQLResult2.getString("fieldE");


/* again, need to store these in another array??

*/

   }

}

   <<Less

Re: How do I initialize an array, and how do I load data into it, and how do I retrieve it?

Posted By:   Arun_Bharathan  
Posted On:   Monday, November 12, 2001 01:31 PM

Okay, this might be silly but can't you just join the table use a query like this
 
Select a.fieldA,a,fieldB,a.fieldC,b.fieldD, b.fieldE from tableone a, tabletwo b where b.secondfieldA = a.fieldA


Anyway, since you don't know the number of rows returned, you could collect the elements in a vector. (or in some way find out the number of rows returned and create an array of that size. But then there is no getNumberOfRows() method - Maybe last(), getRow() and then first() again with a scrollable resultSet.)
About | Sitemap | Contact