开发者

rs.getMetaData().getColumnName(i) with aliased columns on mysql

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:

rs.getMetaData().getColumnLabel(i);

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜