What Is Database Metadata? in JDBC

The database has emerged as a major business tool across all enterprises, and the concept of database metadata has become a crucial topic. Metadata, which can be broadly defined as “data about data,” refers to the searchable definitions used to locate information. On the other hand, database metadata, which can be broadly defined as “data about database data,” refers to the searchable definitions used to locate database metadata(such as a list of all the tables for a specific schema). For example, you may use database metadata to generate web-based applications. Or, you may use database metadata to reverse-engineer the whole database and dynamically build your desired SQL queries.

JDBC allows clients to discover a large amount of metadata information about a database (including tables, views, columns, stored procedures, and so on) and any given ResultSet via metadata classes.

Most of JDBC’s metadata consists of information about one of two things:

  • java.sql.DatabaseMetaData (database metadata information)
  • java.sql.ResultSetMetaData (metadata information about a ResultSet object)

You should use DatabaseMetaData to find information about your database, such as its capabilities and structure, and use ResultSetMetaData to find information about the results of a SQL query, such as size and types of columns.

JDBC provides the following important interfaces that deal with database and result set metadata:

  • java.sql.DatabaseMetaData: Provides comprehensive information about the database as a whole: table names, table indexes, database product name and version, and actions the database supports. Most of the solutions in this chapter are extracted from our solution class DatabaseMetaDataTool . The DatabaseMetaData interface includes a number of methods that can be used to determine which SQL features are supported by a particular database. According to the JDBC specification, “The java.sql.DatabaseMetaData interface provides methods for retrieving various metadata associated with a database. This includes enumerating the stored procedures in the database, the tables in the database, the schemas in the database, the valid table types, the valid catalogs, finding information on the columns in tables, access rights on columns, access rights on tables, minimal row identification, and so on.” Therefore, DatabaseMetaData methods can be categorized as
    • The schemas, catalogs, tables, views, columns, and column types
    • The database, users, drivers, stored procedures, and functions
    • The database limits (upper and lower bounds, minimums and maximums)
    • The features supported (and those not supported) by the database
  • java.sql.ResultSetMetaData: Gets information about the types and properties of the columns in a ResultSet object.
  • java.sql.ParameterMetaData: Gets information about the types and properties of the parameters in a PreparedStatement object. ParameterMetaData, introduced in JDBC 3.0, retrieves information such as the number of parameters in the PreparedStatement, the type of data that can be assigned to the parameter, and whether or not the parameter value can be set to null.
  • javax.sql.RowSetMetaData: Extends the ResultSetMetaData, an object that contains information about the columns in a RowSet object. This interface is an extension of the ResultSetMetaData interface and has methods for setting the values in a RowSetMetaData object. When a RowSetReader object reads data into a RowSet object, it creates a RowSetMetaData object and initializes it using the methods in the RowSetMetaData interface. Then the reader passes the RowSetMetaData object to the rowset. The methods in this interface are invoked internally when an application calls the method RowSet.execute(); an application programmer would not use them directly.

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

JDBC Topics