List All Table Names of Database using Java

We can list all table names of database using java.sql.DatabaseMetaData.getTables() method. The getTables method accepts catalog, schemaPattern, tablenamePattern, types parameters and returns ResultSet where each row is table description.

Each table descriptor contain the following columns:

  1. String TABLE_CAT represents table catalog and can be null
  2. String TABLE_SCHEM represents table schema and can be null
  3. String TABLE_NAME represents table name
  4. String TABLE_TYPE represents table type. Typical types are TABLE, VIEW, SYSTEM TABLE, GLOBAL TEMPORARY, LOCAL TEMPORARY, ALIAS, SYNONYM.
  5. String REMARKS represents explanatory comment on the table
  6. String TYPE_CAT represents types catalog and can be null
  7. String TYPE_SCHEM represents the types schema and can be null
  8. String TYPE_NAME represents type name and can be null
  9. String SELF_REFERENCING_COL_NAME represents name of the designated identifier column of a typed table and can be null
  10. String REF_GENERATION specifies how values in SELF_REFERENCING_COL_NAME are created. REF_GENERATION possible values are SYSTEM, USER, DERIVED. It’s can be null also

example to list all table names of database using java

output:-

In the above example We use rs.getString(3) because TABLE_NAME row is at third position, We can also write like rs.getString(“TABLE_NAME”).

Leave a Reply

Your email address will not be published. Required fields are marked *