What Is JDBC Metadata Programming? JDBC

JDBC metadata programming is very similar to JDBC programming with one exception: you deal with metadata instead of data. For example, in JDBC programming you are interested in getting employee data and then processing it, but in JDBC metadata programming, you are not interested in getting actual data, but you want to get metadata(data about data, such as the table names in a database).

In JDBC metadata programming, we’re interested in database metadata and result set metadata. For example, for metadata, we want answers to such questions as

  • What is the list of tables or views available in the database?
  • What are the names and types of the columns in tables or views?
  • What is the signature of a specific stored procedure?

In JDBC, several key interfaces comprise the metadata portion:

  • DatabaseMetaData: Provides information about the database as a whole.
  • ResultSetMetaData: Used to identify the types and properties of the columns in a ResultSet object.
  • RowSetMetaData: An object that contains information about the columns in a RowSet object. This interface is an extension of the ResultSetMetaData interface with methods for setting the values in a RowSetMetaData object.
  • ParameterMetaData: An object that can be used to get information about the types and properties of the parameters in a PreparedStatement object.
  • DriverPropertyInfo: Driver properties for making a connection. The DriverPropertyInfo class is of interest only to advanced programmers who need to interact with a Driver via the method getDriverProperties() to discover and supply properties for connections.

The remaining chapters will dissect these metadata classes and interfaces and will provide detailed information about using them. Figure shows the creation of metadata interfaces and classes.

JDBC’s metadata classes and interfaces

JDBC’s metadata classes and interfaces

Database metadata is most often used by tools or developers who write programs that use advanced, nonstandard database features and by programs that dynamically discover database objects such as schemas, catalogs, tables, views, and stored procedures.

Some of the DatabaseMetaData methods return results in the form of a ResultSet object. The question is how should we handle ResultSet objects as return values? Metadata is retrieved from these ResultSet objects using the normal ResultSet.getXXX() methods, such as getString() and getInt(). To make the metadata useful for any kind of clients, I have mapped these ResultSet objects into XML.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JDBC Topics