If
you do not use AS clauses in SQL queries that produce
joins or unions, or that contain calculated columns, query results
might contain columns with non-unique names or without names. pureQuery
cannot map such columns to properties in the beans that you want to
contain the query results. You can map the columns manually with a
specific set() method.
This set() method
can be useful in at
least two situations:
To handle these cases, you can implement the following method
in the bean that is populated with data from the returned query result:
public void set (String colName, String tableName, int columnIndex, Object setVal)
{
. . .
}
- colName
- The
name of the column from which the value is returned. This
value can be null or an empty string ("").
- tableName
- The name of the table that contains the column. This value can
be null or an empty string ("").
- columnIndex
- An integer that indicates the position of the column within the
query result. The index starts at 1.
Attention: You have
the option of not providing a value for columnIndex.
Changes in the SQL query can change the columnIndex that
is returned for a column. Also, using columnIndex might
limit the set() method to a specific query, rendering
the method useless for other queries. In most cases, tableName and colName are
sufficient for identifying the property to set the value for.
- setVal
- The value
in the column.