aspose file tools*
The moose likes JDBC and the fly likes Getting table name for column Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Getting table name for column" Watch "Getting table name for column" New topic
Author

Getting table name for column

mitrship gupta
Greenhorn

Joined: Jul 25, 2005
Posts: 7
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

Joined: Aug 04, 2004
Posts: 724
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.


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Gareth Faulkner
Greenhorn

Joined: Oct 29, 2004
Posts: 22
I agree, best to avoid using

select *

Add the column names in the select statement.

Gareth
Amit Mathur
Ranch Hand

Joined: Jan 22, 2002
Posts: 49
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?


amit
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31057
    
232

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" ...


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Amit Mathur
Ranch Hand

Joined: Jan 22, 2002
Posts: 49
yeah sure we can do that
but i was just curious to know if there is something specific
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting table name for column