User Guide

314 Developing Web Applications with ColdFusion
Retrieves a list of the column names contained in the query.
The following example retrieves the array of columns and then iterates over the
list, writing each column name back to the user:
// Get the list of columns from the query
String[] columns = query.getColumns() ;
int nNumColumns = columns.length ;
// Print the list of columns to the user
response.write( "Columns in query: " ) ;
for( int i=0; i<nNumColumns; i++ )
{
response.write( columns[i] + " " ) ;
}
Returns:
An array of strings containing the names of the columns in the query.
getData
public String getData(int iRow,
int iCol)
throws IndexOutOfBoundsException
Retrieves a data element from a row and column of the query. Row and column
indexes begin with 1. You can determine the number of rows in the query by
calling getRowCount. You can determine the columns in the query by calling
getColumns.
The following example iterates over the rows of the query and writes the data back
to the user in a simple, space-delimited format:
int iRow, iCol ;
int nNumCols = query.getColumns().length ;
int nNumRows = query.getRowCount() ;
for ( iRow=1; iRow<=nNumRows; iRow++ )
{
for ( iCol=1; iCol<=nNumCols; iCol++ )
{
response.write( query.getData( iRow, iCol ) + " " ) ;
}
response.write( "<BR>" ) ;
}
Parameters:
iRow — Row to retrieve data from (1-based)
iCol — Column to retrieve data from (1-based)
Returns:
The value of the requested data element.