Nearby lessons

15 of 37

JDBC - Metadata

📌 What You Will Learn
  • 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:

In simple words: Metadata is 'data about data' — it describes your information, not the information itself, like the name, type and count of the columns in a table.
  • 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:

TypeGives information aboutHow to get it
DatabaseMetaDataThe database itselfcon.getMetaData()
ResultSetMetaDataA ResultSet's columnsrs.getMetaData()
ParameterMetaDataThe parameters of a PreparedStatementpst.getParameterMetaData()
In simple words: JDBC gives you three kinds of metadata. DatabaseMetaData tells you about the database itself, ResultSetMetaData about the result columns, and ParameterMetaData about the parameters of a prepared statement.

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).

Example02
Loading editor…

ResultSetMetaData — About the Result Columns

rs.getMetaData() gives the structure of the returned rows — useful when you don't know the columns in advance:

Example03
Loading editor…
📝 Key Takeaways
  • 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.

🧠 Test Your Knowledge

4 Questions
Progress: 0 / 4

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.