JDBC ResultSet get columns with table alias

后端 未结 7 967
春和景丽
春和景丽 2020-11-28 13:22

Imagine I have a query like

SELECT * from table1 a, table2 b where (WHATEVER)

Maybe both tables have the same column name. So I though it

7条回答
  •  醉酒成梦
    2020-11-28 13:35

    One idea I had is to use the getTableName(iCol) to grab the table names for the duplicately-named columns, then wrap a hash of your own keys (with the table name prefix) that would point you to the correct column index, and reference your column-values that way. This would require an initial loop through the meta data at the beginning to set up. The only issue I see with this is that you are aliasing the table names as well. I've yet to find a way of getting those table name aliases from jdbc without managing it yourself when you build the sql statement. This solution would depend on what the syntactical pay-off would be to you.

提交回复
热议问题