Search code examples
javadatabase-tabledatabase-metadata

Get name of current table by resultSet on RowMapper


It's possible get name of current table, on implementation of RowMapper. I try by metadata, but not have sucess


Solution

  • You can try to determine the tablename by

     ResultSet.getMetaData().getTableName(int column)
    

    As both ResultSet and ResultSetMetaData are only interfaces, the implementation depends on the database driver your are using.

    So, if this method does not deliver the tablename:

    • the driver implementation does not support it.
    • the column does not have a table associated with (e.g. select sysdate ...)

    For example current oracle db driver does not support it.

    For H2, check http://www.h2database.com/html/features.html , it describes the behaviour of getTableName() depending on the selected Compatibility Mode.