can i get table name in join select query form ResultSetMetaData

1.8k Views Asked by At

Can I get table name from

ResultSetMetaData
query is join of multiple tables

example

select * from table1 , table 2

when I am going to try to retrieve table name from

ResultSetMetaData
I always founds empty value.

Note : I am using informix driver

2

There are 2 best solutions below

0
On BEST ANSWER

Based on the Informix JDBC Guide, the driver is unable to retrieve the tablename if the query accesses more than one table and will return a single space instead:

ResultSetMetaData.getTableName()

Returns the table name for SELECT, INSERT, and UPDATE statements

SELECT statements with more than one table name and all other statements return a String object containing one blank space.

From: Unsupported methods and methods that behave differently

4
On

You should use it together with column number parameter, so try something like

String table1 = rs.getMetaData().getTableName(someColumnNumberFromFirstTable);    
String table2 = rs.getMetaData().getTableName(someColumnNumberFromSecondTable);

Also see the docs.