Introduction to Some Popular JDBC MetaData Interfaces – Querying Data from Databases

6.3.7.2   Introduction to Some Popular JDBC MetaData Interfaces

In Section 6.3.3.4, we discussed how to use the ResultSet component to retrieve the queried result. Relatively speaking, there are some limitations on using the ResultSet object to get the returned query result. In other words, it is hard to get a clear and detailed picture of the queried result, such as the structure and properties of the data stored in the ResultSet. For example, no information about the returned result, such as the name of the data Table, the total number of columns and each col-umn’s name and data type, would be available when using a ResultSet object to pick up the queried result. In order to solve this problem and get detailed knowledge about the data Table structure, we need to use the ResultSetMetaData component.

The JDBC MetaData Interface provides detailed information about the database and its contents via the JDBC API, and it can be divided into the following three categories:

1) The DatabaseMetaData interface
2) The ResultSetMetaData interface
3) The ParameterMetaData interface

Each class has special functions and operation sequences, and some of them are related when they are utilized in specific ways.

6.3.7.2.1   The DatabaseMetaData Interface

The DatabaseMetaData interface contains more than 150 methods and provides detailed informa-tion about the database as a whole, such as:

  • General information about the database
  • Data source limitations
  • Levels of transaction support
  • Feature support
  • Information about the SQL objects that source includes

In fact, the DatabaseMetaData interface provides methods that allow you to dynamically discover properties of a database as the project runs. Many methods in DatabaseMetaData return information in the ResultSet component, and one can get those pieces of information from the ResultSet object by calling related methods such as getString(), getInt() and getXXX(). A SQLException will be thrown if the queried item is not available in the MetaData interface.

6.3.7.2.2   The ResultSetMetaData Interface

Detailed information about the structure of a queried data Table can be obtained by calling the getMetaData() method that belongs to the ResultSetMetaData class, and a ResultSetMetaData object will be created when the getMetaData() method is executed. Some popular methods included in the ResultSetMetaData class are:

  • getColumnCount()—returns the total number of columns in the ResultSet
  • getColumnName()—returns the column name
  • getColumnType()—returns the column data type
  • getTableName()—returns the data Table name

Similar to the DatabaseMetaData interface, the ResultSetMetaData interface allows users to find the structure of data Tables and properties of columns in Tables.

Leave a Reply

Your email address will not be published. Required fields are marked *


© 2024 vogafloat, LLC ,About, Careers, Contact us,Cookies, Terms, Privacy