• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to refer columns with same name in jdbc

 
suresh venkat
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a join statement :

Select a.col1, a.col2, b.col3, b.col2 from TABLE1 a, TABLE2 b where a.col1 = b.col1

how do I refer with same column name suppose I want to get b.col2

I get error when I try rs.getString("b.col2") or
rs.getString("TABLE2.COL2")..

note I donot want positional retrieval i.e rs.getString(x) , where x is column number.

can you suggest how to refer the b.col2 uniquely.
 
Reid M. Pinchback
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by suresh venkat:
Select a.col1, a.col2, b.col3, b.col2 from TABLE1 a, TABLE2 b where a.col1 = b.col1


select a.col1 "A1", a.col2 "A2", ...

In other words, provide the column in the result with an alias.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4033
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by suresh venkat:
I get error when I try rs.getString("b.col2") or
rs.getString("TABLE2.COL2")..

Name your projection elements such as "SELECT COL2 AS HAPPYCOLUMN" then you can use rs.getString("HAPPYCOLUMN");
 
suresh venkat
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestions -- Suresh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic