Java Reference
In-Depth Information
7.8
Meta Data
Meta data is 'data about data'. There are two categories of meta data available
through the JDBC API:
data about the rows and columns returned by a query (i.e., data about
ResultSet
objects);
data about the database as a whole.
The fi rst of these is provided by interface
ResultSetMetaData
, an object of which
is returned by the
ResultSet
method
getMetaData
. Information available from a
ResultSetMetaData
object includes the following:
the number of fi elds/columns in a
ResultSet
object;
the name of a specifi ed fi eld;
the data type of a fi eld;
the maximum width of a fi eld;
the table to which a fi eld belongs.
Data about the database as a whole is provided by interface
DatabaseMetaData
,
an object of which is returned by the
Connection
method
getMetaData
. However,
most Java developers will rarely fi nd a need for
DatabaseMetaData
and no further
mention will be made of it.
Before proceeding further, it is worth pointing out that the full range of SQL
types is represented in class
java.sql.Types
as a series of 28 named static integer
(
int
) constants. The 8 that are likely to be of most use are listed below.
DATE
DECIMAL
DOUBLE
FLOAT
INTEGER
NUMERIC
REAL
VARCHAR
INTEGER
and
VARCHAR
are particularly commonplace, the latter of these
corresponding to string values.
The example coming up makes use of the following
ResultSetMetaData
methods, which return properties of the database fi elds held in a
ResultSetMetaData
object.
int getColumnCount()
String getColumnName(<colNumber>)
int getColumnType(<colNumber>)
String getColumnTypeName(<colNumber>)
Search WWH ::
Custom Search