Java DatabaseMetaData interface

DatabaseMetaData interface provides methods to get meta data of a database such as database product name, database product version, driver name, name of total number of tables, name of total number of views etc.

Commonly used methods of DatabaseMetaData interface

  1. public String getDriverName()throws SQLException: it returns the name of the JDBC driver.
  2. public String getDriverVersion()throws SQLException: it returns the version number of the JDBC driver.
  3. public String getUserName()throws SQLException: it returns the username of the database.
  4. public String getDatabaseProductName()throws SQLException: it returns the product name of the database.
  5. public String getDatabaseProductVersion()throws SQLException: it returns the product version of the database.
  6. public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types)throws SQLException: it returns the description of the tables of the specified catalog. The table type can be TABLE, VIEW, ALIAS, SYSTEM TABLE, SYNONYM etc.

How to get the object of DatabaseMetaData:

The getMetaData() method of Connection interface returns the object of DatabaseMetaData. Syntax:

Simple Example of DatabaseMetaData interface :

Flash Soon


Example of DatabaseMetaData interface that prints total number of tables :

Flash Soon


Example of DatabaseMetaData interface that prints total number of views :

Flash Soon



Advertisement

© Sapster 2017