It is unfortuate that the Javadocs for ResultSet.getXXX(String
columnName) do not make the distinction between whether you should pass
in a column name or its label -- really you need to pass in the column's
label.
Consider a select on two tables that happen to have matching column names.
SELECT a.c1, b.c1 FROM a, b where a.c2 = b.c2
What should the JDBC driver return from a rs.getString("c1") in this
case? The column name is not unique.
ANSI Standard SQL provides a workaround via the "AS" clause:
SELECT a.c1 AS "a_c1", b.c1 AS "b_c1" FROM a, b where a.c2 =
b.c2
or if you prefer to use the Sybase SQL dialect alternative:
SELECT a_c1 = a.c1, b_c1 = b.c1 FROM a, b where a.c2 = b.c2
If you change your application to use getColumnLabel instead of
getColumnName I think it will work as you expect.
I believe that the true intent behind RSMD.getColumnName is to be used
in conjunction with getTableName and getSchemaName to allow applications
to dynamically build UPDATE/DELETE statements based on RSMD info to
target the actual underlying tables when aliases have been used in the
query.
###@###.### 2004-02-02
columnName) do not make the distinction between whether you should pass
in a column name or its label -- really you need to pass in the column's
label.
Consider a select on two tables that happen to have matching column names.
SELECT a.c1, b.c1 FROM a, b where a.c2 = b.c2
What should the JDBC driver return from a rs.getString("c1") in this
case? The column name is not unique.
ANSI Standard SQL provides a workaround via the "AS" clause:
SELECT a.c1 AS "a_c1", b.c1 AS "b_c1" FROM a, b where a.c2 =
b.c2
or if you prefer to use the Sybase SQL dialect alternative:
SELECT a_c1 = a.c1, b_c1 = b.c1 FROM a, b where a.c2 = b.c2
If you change your application to use getColumnLabel instead of
getColumnName I think it will work as you expect.
I believe that the true intent behind RSMD.getColumnName is to be used
in conjunction with getTableName and getSchemaName to allow applications
to dynamically build UPDATE/DELETE statements based on RSMD info to
target the actual underlying tables when aliases have been used in the
query.
###@###.### 2004-02-02