0

Has anybody been successful in retrieving the tablename from ResultSetMetaData via the getTableName() for Oracle database ?

All the online materials suggest to set ResultSetMetaDataOptions to "1", but it does not work.

kurast
  • 1,660
  • 3
  • 17
  • 38
Krithika Vittal
  • 1,477
  • 2
  • 16
  • 32

1 Answers1

1

As stated here Information about getTableName():

Hi. Sorry to be the bearer of bad news, but Oracle's DBMS doesn't send the information about what table a column came from, so the oracle driver will never be able to implement that resultset metadata call. Most DBMSes don't either, and so you will see that 99% of all JDBC drivers will also not implement that call to return anything useful. Only Sybase, with their very latest driver and a specific optional DBMS configuration, have done it. It takes a change in the DBMS that most DBMS vendors will never bother to do.

Edit: I tried below approach to set the parameter:

java.util.Properties info = new java.util.Properties();
info.put ("user", "scott");
info.put ("password", "tiger");
info.put ("ResultSetMetaDataOptions", "1");

Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@myhost:1521:orcl", info);

However, it didn't work - I was still unable to get the table name. This property is not on the list of possible properties which you can check here: Driver documentation. I was also unable to find any other way to set that property and get it to work.

Przemyslaw Kruglej
  • 8,003
  • 2
  • 26
  • 41
  • When the ResultSetMetaDataOptions property is set to 1 and the ResultSetMetaData.getTableName() method is called, the table name information that is returned by the Oracle driver depends on whether the column in a result set maps to a column in a table in the database. For each column in a result set that maps to a column in a table in the database, the Oracle driver returns the table name associated with that column. For columns in a result set that do not map to a column in a table (for example, aggregates and literals), the Oracle driver returns an empty string. – Krithika Vittal Oct 17 '13 at 22:04
  • I just want to know how i can set this information ResultSetMetaDataOptions ?!! – Krithika Vittal Oct 17 '13 at 22:05
  • @KrithikaVittal I was unable to get the table name by setting this property to 1. – Przemyslaw Kruglej Oct 18 '13 at 06:14
  • Yes I could not retrieve the table name at all @Przemyslaw Kruglej ... Thanks – Krithika Vittal Jun 20 '14 at 19:03