2

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

3 Answers 3

6

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

3

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
1

You can use temporary tables,

   select rowid as col1, id as col2 INTO #tmp from dummy_table


    select * from #tmp

I think this will work.

For second solution also check String getColumnLabel(int column) function of ResultSetMetaData

1
  • 2
    I think that it is not a good solution. You will add additional io and potentially bad performance. Look at Mark Bannister answer.
    – kolchanov
    Dec 9, 2011 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.