Thursday, September 11, 2008

JDBC ResultSet Column Name with Multiple Tables

For SQL like, "select a.col1, b.col2 from atab a, btab b where a.id=b.aid and b.id=?", when extracting values from ResultSet, what column name to use?

Incorrect - a.col1, b.col2.
Correct - col1, col2.

What if same column names in both tables, like a.col3 and b.col3?

Write SQL like "select a.col3 as acol3, b.col3 as bcol3 ...", then name the column in getXXX method as acol3 and bcol3.