Search code examples
javametadataresultset

Trouble getting table name from meta data from result set


I have gotten some meta data from a result set after running executing some sql statement. I want to get the table name from the meta data. I am using

Metadata.getTableName(1);

But it is returning nothing; what does that mean? Also note that I am able to successfully grab column names from the meta data, just not the table name.


Solution

  • you have to use DatabaseMetaData md = connection.getMetaData();

    From javadoc which retrieves a DatabaseMetaData object that contains metadata about the database to which this Connection object represents a connection. The metadata includes information about the database's tables, its supported SQL grammar, its stored procedures, the capabilities of this connection, and so on.