Reputation: 311
I have the following question, is it possible to read the data from result set by rows? For example if I have read 12 rows by the following statement:
select * from months where data = 'whatever' and place_id = '1'
I can read the data into a string by following code:
while (rs.next())
{
for ( int i=1, y=0; i<numOfCols+1; i++,y++ )
{
out.print("<td>" + rs.getString(i) + "</td>");
avMaxTemp += rs.getString(i) +",";
}
}
If I change the select statement:
select * from months where data = 'whatever' and place_id in ('1', '2')
How will I read the second row of data into:
string avMinTemp =
I tried a lot to play with the loop(s) but it never gave me the results expected. Any help greatly appriciated!!! I need to copy the second row into a string avMinTemp, the third row of data into string meanTemp and so on...
Upvotes: 3
Views: 24058
Reputation: 1077
You have to create a list object before the while statement and add avaMaxTemp to this list (assuming avaMaxTemp is a string)
e.g.:
List<string> avaMaxTempList = new List<string>();
while (rs.next())
{
for ( int i=1, y=0; i<numOfCols+1; i++,y++ )
{
out.print("<td>" + rs.getString(i) + "</td>");
avMaxTemp += rs.getString(i) +",";
}
avaMaxTempList.Add(avaMaxTemp);
}
Upvotes: 4