Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read data by rows from ResultSet

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...

like image 444
Andrei Ivanov Avatar asked May 01 '26 14:05

Andrei Ivanov


1 Answers

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);
}
like image 158
swissben Avatar answered May 03 '26 02:05

swissben



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!