JDBC  «Prev  Next»
Lesson 6

Prepared Statement Update Conclusion

In this module you have learned how to use batch updates and PreparedStatement as part of your Hospital project database design.
Specifically, you have learned to:
  1. Describe what the ResultSetMetaData class offers
  2. Describe several JDBC helper classes
  3. Describe a design approach that will be part of the Hospital Project
  4. Describe the PreparedStatement interface
  5. Describe what batch updates are

ResultSetMetaData

The main purpose of this module was to introduce you to the use of JDBC's result set metadata (the java.sql.ResultSetMetaData interface). ResultSetMetaData provides metadata for the ResultSet object. ResultSetMetaData enables us to get information about the types and properties of the columns in a ResultSet object. Typically, IDEs and GUI tools often use the JDBC ResultSetMetaData class to get information about data in a particular table. In order to help you understand this interface, I will list some important questions about metadata for ResultSet objects and then answer each one in detail. Before delving into ResultSetMetaData, we will look at the meaning of metadata. Note that ResultSetMetaData is an important interface in JDBC since RowSetMetaData extends this interface.

ResultSetMetaDataTool. This class gives you ready-to-use public static methods for answering the questions listed in this module. For answering questions about result set metadata, I list portions of these classes at some sections, but the complete class definitions (including JavaDoc-style comments) is given in the Source Code section of the website. All of the methods in this chapter are static, and each method is written to be as independent as possible. Whenever possible, the methods will return the result as XML (serialized as a String object, which can be easily converted to an XML document org.w3c.dom.Document).
I will provide a utility class, DocumentManager, which can
  1. Convert org.w3c.dom.Document to XML as a serialized String object
  2. Convert XML as a serialized String object into an XML document, org.w3c.dom.Document

In general, it is efficient to create XML as a serialized String object. The jcb package and all its associated classes will be available from the website as well. For some questions in this chapter, I will combine all of our answers into a single XML output. This can save lots of time and enables a client to get all of the required information regarding result set metadata with a single call (this way, you can improve performance of your database applications for metadata access

What Is ResultSet Metadata?

Metadata is data about data, which provides structured descriptive information about other data. Result set metadata relieves the user of having to obtain full knowledge of the characteristics of relational databases in advance. Therefore, we conclude that metadata describes the data and its properties, but is not the actual data itself. For example, the records in a card catalog in a local library give brief details about the actual book. A record provides enough information to know what the book is called, its unique identification number, and how and where to find it. These details are metadata, in this case, bibliographic elements such as author, title, abstract, publisher, and published date.

Object Structure

ResultSet metadata enables dynamic discovery of a ResultSet object's structure. Typically, most JDBC programmers will be programming with knowledge of their target database's schema definitions (the names of tables, views, columns, and their associated types). In this case, programmers can use the strongly typed JDBC interfaces. However, there is also another important class of database access where an application (or an application builder) dynamically generates the result sets from ad hoc queries (submitted by different clients). This chapter describes the JDBC support for dynamic access. ResultSet metadata has many applications. It can be used to
  1. Discover the number of columns, column names, types, and length
  2. Find out the table names for all columns in the result set
  3. Determine whether a given column is readable/writable
  4. Determine whether a given column is searchable (indicates whether the designated column can be used in a SQL WHERE clause or in SQL SELECT, UPDATE, and DELETE queries)
As we observe, metadata not only enables us to do effective management of resources, but also helps us to use metadata to find the data we need and determine how best to use it. Also, metadata provides structured descriptions of database information resources and services.
In the next module, you will start to learn about stored procedures and transactions.