Thread: ResultsetMetaData.getColumnName bug?

ResultsetMetaData.getColumnName bug?

From
"Roy Smith"
Date:
It looks like getColumnName() is incorrectly returning the column label.
They are normally the same, but I have a query "select add as Address" and resultsetmetadata.getColumnName(1) is retuning "Address" instead of "add".

In the source code of AbstractJdbc2ResultsetMetadata I see this ...

   public String getColumnName(int column) throws SQLException
    {
        return getColumnLabel(column);
    }



best
Roy

Re: ResultsetMetaData.getColumnName bug?

From
Kris Jurka
Date:

On Sat, 8 Dec 2007, Roy Smith wrote:

> It looks like getColumnName() is incorrectly returning the column label.
> They are normally the same, but I have a query "select add as Address" and
> resultsetmetadata.getColumnName(1) is retuning "Address" instead of "add".
>

This has been discussed before (see archives), but the simplest
explanation is that rs.getXXX(rsmd.getColumnName(1)) should work and
won't if we return the base column name.  To get the result you want use
((PGResultSetMetaData)rsmd).getBaseColumnName().

Kris Jurka