public abstract interface Query
Interface to a query used or created by a CustomTag. A query contains tabular data organized by named columns and rows.
Adds a row to a query. Call this method to append a row to a query.
Returns the index of the row that was appended to the query.
public int addRow()
The following example demonstrates the addition of two rows to a query that has three columns, 'City', 'State', and 'Zip':
// Define column indexes
int iCity = 1, iState = 2, iZip = 3 ; // First row int iRow = query.addRow() ; query.setData( iRow, iCity, "Minneapolis" ) ; query.setData( iRow, iState, "MN" ) ; query.setData( iRow, iZip, "55345" ) ; // Second row iRow = query.addRow() ; query.setData( iRow, iCity, "St. Paul" ) ; query.setData( iRow, iState, "MN" ) ; query.setData( iRow, iZip, "55105" ) ;
Returns the index of the column, or -1 if no such column exists.
public int getColumnIndex(String name)
Parameter | Description |
---|---|
name |
Name of column to get index of (lookup is case insensitive) |
The following example retrieves the index of the EMAIL column and uses it to output a list of the addresses contained in the column:
// Get the index of the EMAIL column
int iEMail = query.getColumnIndex( "EMAIL" ) ; // Iterate over the query and output list of addresses int nRows = query.getRowCount() ; for( int iRow = 1; iRow <= nRows; iRow++ ) { response.write( query.getData( iRow, iEMail ) + "<BR>" ) ; }
Returns an array of strings containing the names of the columns in the query.
public String[] getColumns()
The following example retrieves the array of columns, 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] + " " ) ; }
Retrieves a data element from a row and column of a query. Row and column indexes begin with 1. You can find the number of rows in a query by calling getRowCount
. You can find the number of columns in a query by calling getColumns
.
Returns the value of the requested data element.
public String getData(int iRow, int iCol)
IndexOutOfBoundsException
If an invalid index is passed to the method
Parameter | Description |
---|---|
iRow |
Row to retrieve data from (1-based) |
iCol |
Column to retrieve data from (1-based) |
The following example iterates over the rows of a 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>" ) ; }
public String getName()
The following example retrieves the name of a query and writes it back to the user:
Query query = request.getQuery() ;
response.write( "The query name is: " + query.getName() ) ;
Retrieves the number of rows in a query.
Returns the number of rows contained in a query.
The following example retrieves the number of rows in a query and writes it back to the user:
Query query = request.getQuery() ;
int rows = query.getRowCount() ; response.write( "The number of rows in the query is " + Integer.toString(rows) ) ;
Sets a data element in a row and column of a query. Row and column indexes begin with 1. Before calling setData
for a given row, call addRow
and use the return value as the row index for your call to setData
.
public void setData(int iRow, int iCol, String data)
IndexOutOfBoundsException
If an invalid index is passed to the method
Parameter | Description |
---|---|
iRow |
Row of data element to set (1-based) |
iCol |
Column of data element to set (1-based) |
data |
New value for data element |
The following example demonstrates the addition of two rows to a query that has three columns, 'City', 'State', and 'Zip':
// Define column indexes
int iCity = 1, iState = 2, iZip = 3 ; // First row int iRow = query.addRow() ; query.setData( iRow, iCity, "Minneapolis" ) ; query.setData( iRow, iState, "MN" ) ; query.setData( iRow, iZip, "55345" ) ; // Second row iRow = query.addRow() ; query.setData( iRow, iCity, "St. Paul" ) ; query.setData( iRow, iState, "MN" ) ; query.setData( iRow, iZip, "55105" ) ;