DB2 Version 9.7 for Linux, UNIX, and Windows

Examples of ResultSetMetaData.getColumnName and ResultSetMetaData.getColumnLabel values

For the IBM® Data Server Driver for JDBC and SQLJ version 4.0 and later, the default behavior of ResultSetMetaData.getColumnName and ResultSetMetaData.getColumnLabel differs from the default behavior for earlier JDBC drivers. You can use the useJDBC4ColumnNameAndLabelSemantics property to change this behavior.

The following examples show the values that are returned for IBM Data Server Driver for JDBC and SQLJ Version 4.0, and for previous JDBC drivers, when the useJDBC4ColumnNameAndLabelSemantics property is not set.

All queries use a table that is defined like this:
CREATE TABLE MYTABLE(INTCOL INT)
Example: The following query contains an AS CLAUSE, which defines a label for a column in the result set:
SELECT MYCOL AS MYLABEL FROM MYTABLE

The following table lists the ResultSetMetaData.getColumnName and ResultSetMetaData.getColumnName values that are returned for the query:

Table 1. ResultSetMetaData.getColumnName and ResultSetMetaData.getColumnName before and after IBM Data Server Driver for JDBC and SQLJ Version 4.0 for a query with an AS CLAUSE
Target data source Behavior before IBM Data Server Driver for JDBC and SQLJ Version 4.0 Behavior for IBM Data Server Driver for JDBC and SQLJ Version 4.0 and later
getColumnName value getColumnLabel value getColumnName value getColumnLabel value
DB2® for Linux, UNIX, and Windows MYLABEL MYLABEL MYCOL MYLABEL
IBM Informix® MYLABEL MYLABEL MYCOL MYLABEL
DB2 for z/OS® Version 8 or later, and DB2 UDB for iSeries® V5R3 and later MYLABEL MYLABEL MYCOL MYLABEL
DB2 for z/OS Version 7, and DB2 UDB for iSeries V5R2 MYLABEL MYLABEL MYLABEL MYLABEL
Example: The following query contains no AS clause:
SELECT MYCOL FROM MYTABLE

The ResultSetMetaData.getColumnName and ResultSetMetaData.getColumnLabel methods on the query return MYCOL, regardless of the target data source.

Example: On a DB2 for z/OS or DB2 for i data source, a LABEL ON statement is used to define a label for a column:
LABEL ON COLUMN MYTABLE.MYCOL IS 'LABELONCOL'
The following query contains an AS CLAUSE, which defines a label for a column in the ResultSet:
SELECT MYCOL AS MYLABEL FROM MYTABLE

The following table lists the ResultSetMetaData.getColumnName and ResultSetMetaData.getColumnName values that are returned for the query.

Table 2. ResultSetMetaData.getColumnName and ResultSetMetaData.getColumnName before and after IBM Data Server Driver for JDBC and SQLJ Version 4.0 for a table column with a LABEL ON statement in a query with an AS CLAUSE
Target data source Behavior before IBM Data Server Driver for JDBC and SQLJ Version 4.0 Behavior for IBM Data Server Driver for JDBC and SQLJ Version 4.0 and later
getColumnName value getColumnLabel value getColumnName value getColumnLabel value
DB2 for z/OS Version 8 or later, and DB2 UDB for iSeries V5R3 and later MYLABEL LABELONCOL MYCOL MYLABEL
DB2 for z/OS Version 7, and DB2 UDB for iSeries V5R2 MYLABEL LABELONCOL MYCOL LABELONCOL
Example: On a DB2 for z/OS or DB2 for i data source, a LABEL ON statement is used to define a label for a column:
LABEL ON COLUMN MYTABLE.MYCOL IS 'LABELONCOL'
The following query contains no AS CLAUSE:
SELECT MYCOL FROM MYTABLE

The following table lists the ResultSetMetaData.getColumnName and ResultSetMetaData.getColumnName values that are returned for the query.

Table 3. ResultSetMetaData.getColumnName and ResultSetMetaData.getColumnName before and after IBM Data Server Driver for JDBC and SQLJ Version 4.0 for a table column with a LABEL ON statement in a query with no AS CLAUSE
Target data source Behavior before IBM Data Server Driver for JDBC and SQLJ Version 4.0 Behavior for IBM Data Server Driver for JDBC and SQLJ Version 4.0
getColumnName value getColumnLabel value getColumnName value getColumnLabel value
DB2 for z/OS Version 8 or later, and DB2 UDB for i5/OS™ V5R3 and later MYCOL LABELONCOL MYCOL MYCOL
DB2 for z/OS Version 7, and DB2 UDB for i5/OS V5R2 MYCOL LABELONCOL MYLABEL LABELONCOL