java - Using ResultSetMetaData with same column name in 2 tables -


this question has answer here:

i want column names 2 tables , value using resultsetmetadata , resultset. let's table mytable has columns x, y , z. do

 select * table mytable a,mytable b a.x = b.y 

and want use b.z 's value in code.

resultsetmetadata list columns x y z x y z , how differentiate z's value aliases , b?

i need use * in query since improves performance. can't mention column names there. there way can value of column b.z using column names of resultset? mean there way resultsetmetadata list columns a.x, a.y, a.z, b.x, b.y, , b.z ?

if can't or don't want specify columnnames (with aliases), need retrieve values index, not column label. resultset api doc explicitly says:

when getter method called column name , several columns have same name, value of first matching column returned. column name option designed used when column names used in sql query generated result set. for columns not explicitly named in query, best use column numbers. if column names used, programmer should take care guarantee uniquely refer intended columns, can assured sql clause.

(emphasis mine)

if want differentiate between columns can use resultsetmetadata.gettablename, won't retrieval (except find "right" index use). note not databases support providing table name.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -