Nearby lessons
15 of 37JDBC - Metadata
- What metadata means and the three metadata types in JDBC
- DatabaseMetaData — information about the database
- ResultSetMetaData — information about query results
- The ResultSet types: forward-only, scrollable, updatable
- What RowSets are and how they improve on ResultSet
Metadata is a fundamental part of database programming with JDBC. This lesson explains What is Metadata?, DatabaseMetaData — About the Database and ResultSetMetaData — About the Result Columns with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
What is Metadata?
Metadata means 'data about data'. It is extra information about your actual data — not the data itself. Examples:
- About the database: its product name, version.
- About a ResultSet: how many columns, each column's name and type.
JDBC provides three types of metadata:
| Type | Gives information about | How to get it |
|---|---|---|
| DatabaseMetaData | The database itself | con.getMetaData() |
| ResultSetMetaData | A ResultSet's columns | rs.getMetaData() |
| ParameterMetaData | The parameters of a PreparedStatement | pst.getParameterMetaData() |
DatabaseMetaData — About the Database
getMetaData() on a Connection returns a DatabaseMetaData object with methods to describe the database:
DatabaseMetaData can also tell you whether the database supports a feature, like scrollable ResultSets: dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE).
ResultSetMetaData — About the Result Columns
rs.getMetaData() gives the structure of the returned rows — useful when you don't know the columns in advance:
- Metadata = data about data; JDBC has three kinds (Database, ResultSet, Parameter).
- DatabaseMetaData (con.getMetaData()) describes the database and its tables.
- ResultSetMetaData (rs.getMetaData()) describes the columns of a result.
- ResultSet types: FORWARD_ONLY, SCROLL_INSENSITIVE, SCROLL_SENSITIVE.
- Concurrency: READ_ONLY or UPDATABLE.
- RowSets are flexible, scrollable, and can work disconnected from the database.