Meta-Data
Much of what you have done with JDBC so far requires you to know a lot about the database you are using, including the capabilities of the database engine and the data model against which you are operating. Requiring this level of knowledge may not bother you much, but JDBC does provide the tools to free you from these limitations. These tools come in the form of meta-data.
The term “meta” here means information about your data
that does not interest the end users at all, but which you need to
know in order to handle the data. JDBC provides two meta-data
classes: java.sql.ResultSetMetaData and
java.sql.DatabaseMetaData. The meta-data described
by these classes was included in the original JDBC
ResultSet and Connection
classes. The team that developed the JDBC specification decided
instead that it was better to keep the ResultSet
and Connection classes small and simple to serve
the most common database requirements. The extra functionality could
be served by creating meta-data classes to provide the often esoteric
information required by a minority of developers.
Result Set Meta-Data
As its name implies, the
ResultSetMetaData
class provides extra information about
ResultSet objects returned from a database query.
In the embedded queries you made earlier in the book, you hardcoded
into your queries much of the information a
ResultSetMetaData object gives you. This class
provides you with answers to the following questions:
How many columns are in the result set?
Are column ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access