The DatabaseMetaData interface is implemented by the IBM® Developer Kit for Java™ JDBC driver to provide information about its underlying data sources. It is used primarily by application servers and tools to determine how to interact with a given data source. Applications may also use DatabaseMetaData methods to obtain information about a data source, but this is less typical.
The DatabaseMetaData interface includes over 150 methods that can be categorized according to the types of information they provide. These are described below. The DatabaseMetaData interface also contains over 40 fields that are constants used as return values for various DatabaseMetaData methods.
See "Changes in JDBC 3.0" below for information about changes made to methods in the DatabaseMetaData interface.
A DatabaseMetaData object is created with the Connection method getMetaData. Once the object is created, it can be used to dynamically find information about the underlying data source. The following example creates a DatabaseMetaData object and uses it to determine the maximum number of characters allowed for a table name:
Example: Create a DatabaseMetaData object
// con is a Connection object DatabaseMetaData dbmd = con.getMetadata(); int maxLen = dbmd.getMaxTableNameLength();
Some DatabaseMetaData methods are used to dynamically find general information about a data source as well as to obtain details about its implementation. Some of these methods include the following:
A large group of DatabaseMetaData methods can be used to determine whether a given feature or set of features is supported by the driver or underlying data source. Beyond this, there are methods that describe what level of support is provided. Some of the methods that describe support for individual features include the following:
Methods to describe a level of feature support include the following:
Another group of methods provide the limits imposed by a given data source. Some of the methods in this category include the following:
Methods in this group return the limit value as an integer. A return value of zero means that there is either no limit or the limit is unknown.
A number of DatabaseMetaData methods provide information about the SQL objects that populate a given data source. These methods can determine the attributes of SQL objects. These methods also return ResultSet objects in which each row describes a particular object. For example, the getUDTs method returns a ResultSet object in which there is a row for each user-defined table (UDT) that has been defined in the data source. Examples of this category include the following:
A small group of methods provide information about the transaction semantics supported by the data source. Examples of this category include the following:
See Example: DatabaseMetaData interface for IBM Developer Kit for Java for an example of how to use the DatabaseMetaData interface.
There are changes to the return values for some of the methods in JDBC 3.0. The following methods have been updated in JDBC 3.0 to add fields to the ResultSets that they return.