Folks,
Is it mandatory to use an ALIAS when we are doing some operation on the column?
Ex: select upper(col1) from table1
when i am trying to retrieve the resultset by rs.getString("col1"), it was giving this exception
COM.ibm.db2.jdbc.DB2Exception: [IBM][JDBC Driver] CLI0611E Invalid column name. SQLSTATE=S0022
when I changed the query to:
select upper(col1) as col1 from table1 and used rs.getString("col1"), it is working fine.
So, is it mandatory to use an ALIAS when some function like upper,trim,lower was applied on a column???
I am using: DB2 8.2, Type 2 driver
Thanks
Best Answer
The expression UPPER(COL1) is not the same thing as COL1.
Compare this:
To this:
Notice that the column names in each result set (sqlname.data) are not the same.
So, you would have either have to use a column alias or use rs.getString("1").