Java Reference
In-Depth Information
The most noticeable effects of modifying the example to handle different RDBMS systems and different
drivers are how minimal the required changes are and how pronounced a difference it makes to use the
Opta2000 driver instead of the
jdbc:odbc
bridge in terms of speed.
Using DatabaseMetaData
The DatabaseMetaData interface provides the following types of information about the database:
General information about the data source, including:
Database product name and version
Driver name
Database URL
Feature support, such as:
SQL92 Support level
SQL keywords recognized
Transaction Isolation levels supported
Support of features such as batch updates
Data-source limits including:
The maximum number of columns in a table
The maximum lengths of column and table names
Information about the SQL objects the source contains, such as:
The types of tables in a catalog
The names of all tables of each type
Information about all columns in the tables
Many of the DatabaseMetaData methods return information in
ResultSets
, allowing you to use
ResultSet
methods such as
getString()
and
getInt()
to retrieve this information. If a given form
of metadata is not available, these methods throw a SQLException. The
next section
illustrates how to
retrieve information about the database.
Retrieving Information about the Database
Figure 10-2
illustrates the kind of information you can get about a database using the
DatabaseMetaData
object. The
JTree
displays the types of tables in the database, with the table
names of each type of table displayed as child nodes of the table type. Tables can be expanded to
display column names, and the columns themselves can be expanded to show information about the
column.
Figure 10-2:
Tree view of tables in a database