when I have a query result for something like:
select col as newName from table;
and I then do (in java) :
rs.getMetaData().getColumnName(i)
it returns the name of the column instead of “newName”…
if however I do
select concat(col,'') as newName from table;
it returns the expected “newName”
is there a way to get the “newName” without messing with tho sql query?
This is all mysql, java, tomcat 6.
Try using
getColumnLabel()instead:FYI, I did a test and
rs.getMetaData().getColumnName(i)worked for me – ie it gave me the alias, not the column name, but perhaps you are using an older version of the JDBC driver and/or mysql database.