Dynamic Database Access
So far we have dealt with applications where you know exactly what
needs to be done at compile time. If this were the only kind of
database support that JDBC provided, no one could ever write tools
like the mysql and msql
interactive command line tools that determine SQL calls at runtime
and execute them. The JDBC
Statement
class provides the
execute()
method for executing SQL that may be
either a query or an update. Additionally,
ResultSet
instances provide runtime information
about themselves in the form of an interface called
ResultSetMetaData
which you can access via the
getMetaData()
call in the
ResultSet
.
Meta Data
The term meta data sounds officious, but it is
really nothing other than extra data about some object that would
otherwise waste resources if it were actually kept in the object. For
example, simple applications do not need the name of the columns
associated with a
ResultSet
—the
programmer probably knew that when the code was written. Embedding
this extra information in the ResultSet
class is
thus not considered by JDBC’s designers to be core to the
functionality of a ResultSet
. Data such as the
column names, however, is very important to some database
programmers—especially those writing dynamic database access.
The JDBC designers provide access to this extra information—the
meta data—via the
ResultSetMetaData
interface. This class specifically
provides:
The number of columns in a result set
Whether
NULL
is a valid value for a columnThe ...
Get MySQL and mSQL now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.