Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jbdc ignores aliases in sql statement

In my java app I running sql query for example:

select rowid as col1, id as col2 from dummy_table

and then, when I use ResultSetMetaData.getColumnNames I expect to get column aliases (col1 and col2), but method returns physical column names.

So, my question is, how to get column aliases using ResultSetMetaData

I use Java 1.6, Jdbc, Sybase

Thanks a lot

like image 473
glebreutov Avatar asked Feb 03 '26 12:02

glebreutov


2 Answers

Maybe your driver doesn't understand aliased column. Try to invoke ResultSetMetaData.getColumnLabel() to see what it get

like image 152
korifey Avatar answered Feb 06 '26 05:02

korifey


I have noticed something similar in MySQL - there, a quick fix is to turn your main query into a sub query, like so:

select v.* from (
select rowid as col1, id as col2 from dummy_table
) as v