Chapter 9: Accessing Database Metadata

This chapter introduces the database metadata APIs. Such APIs are used to discover database objects and their properties at runtime: They provide key mechanisms to build highly dynamic applications. An important aspect of dynamic programs is their genericness. In addition to using metadata interfaces, dynamically typed data access is a strategy to achieve such genericness. This is covered as well in this chapter.

Metadata Interfaces

Metadata interfaces are useful to query a database or a ResultSet for meta information. Meta information about database objects may not be known at development time; therefore developers must either write very generic programs or make use of techniques to discover database objects and their properties at runtime. This chapter covers three types of metadata interfaces: DatabaseMetaData, ResultSetMetaData, and ParameterMetaData. The DatabaseMetaData interface provides many interesting methods for discovering database behaviors, default values, supported functions, and so on. Programmers can use this interface when a program needs to find out at runtime what is allowed and what is not with a particular database, for exam- ple. The ResultSetMetaData interface is probably used more often because it provides information on ResultSets that are, indeed, results of user queries. The ParameterMetaData interface provides information about parameters used with dynamic SQL and stored procedures.

The scope of database metadata is very broad. One of its most interesting uses is to obtain information on the database objects themselves.

A DatabaseMetaData object is obtained from the Connection object created for a given database, as shown in the following:

Connection

DatabaseMetaData getMetaData();

A database can provide information on its objects, such as tables, stored procedures, SQL grammar, and various properties. All this information is obtain- able through methods that apply to a DatabaseMetaData object. The call to getMetaData() returns such an object. Listing 9-1, later in this chapter, provides an example of a call to this method.



JDBC 3. 0. JAVA Database Connectivity
JDBC 3: Java Database Connectivity
ISBN: 0764548751
EAN: 2147483647
Year: 2002
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net