Sharjeel Afzal
Sharjeel Afzal

Reputation: 145

can i get table name in join select query form ResultSetMetaData

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

Upvotes: 0

Views: 1913

Answers (2)

Mark Rotteveel
Mark Rotteveel

Reputation: 108971

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

Upvotes: 1

Petr Mensik
Petr Mensik

Reputation: 27496

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.

Upvotes: 0

Related Questions