• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting table name for column

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree, best to avoid using

select *

Add the column names in the select statement.

Gareth
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah sure we can do that
but i was just curious to know if there is something specific
 
reply
    Bookmark Topic Watch Topic
  • New Topic