JDBC Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 2.11

Commonly Used DatabaseMetaData Methods

This section provides a list of commonly used DatabaseMetaData methods for obtaining information on database objects like tables, and stored procedures.

JDBC database meta data is a collection of information reported by the JDBC driver about the connected database. This collection of information can be obtained by con.getMetaData as a DatabaseMetaData object. Detailed information can be retrieved with various methods offered on the DatabaseMetaData object. Some of them are:

  • getDatabaseProductName() - Retrieves the name of this database product.
  • getDatabaseProductVersion() - Retrieves the version number of this database product.
  • getDriverName() - Retrieves the name of this JDBC driver.
  • getDriverVersion() - Retrieves the version number of this JDBC driver as a String.
  • getJDBCMinorVersion() - Retrieves the minor JDBC version number for this driver.
  • getJDBCMajorVersion() - Retrieves the major JDBC version number for this driver.
  • getUserName() - Retrieves the user name as known to this database.
  • getCatalogs() - Retrieves the catalog names available in this database.
  • getSchemas(String catalog, String schemaPattern) - Retrieves the schema names available in this database.
  • getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) - Retrieves a description of the tables available in the given catalog.
  • getPrimaryKeys(String catalog, String schema, String table) - Retrieves a description of the given table's primary key columns.
  • getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) - Retrieves a description of table columns available in the specified catalog.
  • getProcedures(String catalog, String schemaPattern, String procedureNamePattern) - Retrieves a description of the stored procedures available in the given catalog.
  • getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) - Retrieves a description of the given catalog's stored procedure parameter and result columns.
  • getFunctions(String catalog, String schemaPattern, String functionNamePattern) - Retrieves a description of the system and user functions available in the given catalog.
  • getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) - Retrieves a description of the given catalog's system or user function parameters and return type.

Sections in This Chapter

Commonly Used DatabaseMetaData Methods

Getting Database Server and Driver Info

Listing All Databases - getCatalogs()

Listing All Schemas - getSchemas()

Listing All Tables - getTables()

Listing All Culumns - getColumns()

Listing All Stored Procedures - getProcedures()

Dr. Herong Yang, updated in 2007
Commonly Used DatabaseMetaData Methods