Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting table name for column

 
mitrship gupta
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone
i want to know if there is a way to get the table name for a column from a resultSet
thers a method getTableName(int) in ResultSetMetaData but tht doesnt seem to work in ORACLE.i havnt tested it in SQL SERVER.
its returning empty string!!!
my prob is tht is in sql query there is a ambigous column, is there any way to know the table name with help of ResultSet returned by the query???
eg. select * from EMP,EMPPROJECT
EMP{ID,AGE} PROJECT{ID,STARTDATE}
In this case Resultset returned contains to column with name ID so is there any way tht i can differentiate these columns except the order in which they are returned???

Thaking in advance

regards
Saurabh
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, not only in JDBC is better to use full name of column
like
emp.id, project.id
then you will have no such problem.
 
Gareth Faulkner
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree, best to avoid using

select *

Add the column names in the select statement.

Gareth
 
Amit Mathur
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup , best thing is to avoid 'Select *'.

But its an interesting question still - can we get to know table name for a specific column retrieved in my result set?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amit Mathur:
can we get to know table name for a specific column retrieved in my result set?

You can if you rename the column in the SQL query. A bit of a hack though.

select field1 as "table1_field1", field2 as "table2_field2" ...
 
Amit Mathur
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah sure we can do that
but i was just curious to know if there is something specific
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic