Iterating through the rows and columns

You must process each column value of each row one at a time. In this example, the processing is contained in a method (which you can reuse in other applications) called printResultSet(). printResultSet() takes the result set rs as an input parameter.

  printResultSet(rs.in()); 

The method uses the length() method to determine how many columns, nc, are in the result set, rs, and displays the number of columns and rows; the number of rows is represented by the variable rows. The method uses a for loop to iterate through each row, row, in the result set; and a nested for loop to iterate through each column, column, in the current row. The method must check for null values before it can process and print the values in each of the columns of the current row. After checking for and printing out null values, the method continues to the next column in the current row.

void printResultSet(const ResultSet& rs)
{ 
  ULong nc = rs.columns.length(); 
  cout << rs.rows << " rows, " << nc << " columns" << endl; 
  for (ULong row = 0; row < rs.rows; row++) 
  { 
    cout << "row " << row << ": "; 
    for (ULong column = 0; column < nc; column++) 
    { 
      if (column > 0) 
      { 
        cout << ", "; 
      } 
      BooleanSeq& nulls =            ((ColumnSeq&)rs.columns)[column].nulls; 

      if (row + 1 <= nulls.length() && nulls[row]) 
      { 
        cout << "null"; 
        continue; 
      }