How Do You Get a RowSet's Metadata? JDBC

A RowSet (javax.sql.RowSet) object contains a set of rows from a result set (ResultSet) or some other source of tabular data, like a file or spreadsheet. Because a RowSet object follows the JavaBeans model for properties and event notification, it is a JavaBeans component that can be combined with other components in an application. As is true with other Beans, application programmers will probably use a development tool to create a RowSet object and set its properties. Rowsets may have many different implementations to fill different needs. These implementations fall into two broad categories, rowsets that are connected and those that are disconnected. A disconnected rowset gets a connection to a data source in order to fill itself with data or to propagate changes in data back to the data source, but most of the time it does not have a connection open. While it is disconnected, it does not need a JDBC driver or the full JDBC API, so its footprint is very small. Thus a rowset is an ideal format for sending data over a network to a thin client.

RowSetMetaData(defined in the javax.sql package) is an object that contains information about the columns in a RowSet object. This interface is an extension of the ResultSetMetaData interface with methods for setting the values in a RowSetMetaData object. When a RowSetReader object reads data into a RowSet object, it creates a RowSetMetaData object and initializes it using the methods in the RowSetMetaData interface. Then the reader passes the RowSetMetaData object to the rowset.

A RowSetMetaData object’s format is not suitable for web-based applications. For this reason, I will provide a Java servlet to display that object in an XML object; a client may extract the desired information from that XML object. Disconnected RowSet objects (such as CachedRowSet and WebRowSet) provide an XML format for their data metadata, and I will take advantage of such methods. Note that one of the main reasons to use a CachedRowSet or WebRowSet object is to pass data between different components of an application. Because it is serializable, a CachedRowSet or WebRowSet object can be used, for example, to send the result of a query executed by an enterprise JavaBeans component running in a server environment over a network to a client running in a web browser.

What follows is a Java servlet, GetRowSetMetaData, which will display SQL queries metadata as an XML object. The signature of GetRowSetMetaData is


You may modify and update this servlet to pass additional dynamic parameters to your SQL queries.

MySQL Database Setup

Oracle Database Setup

The Solution

Invoking GetRowSetMetaData for MySQL

Figure : shows how to run the solution for the MySQL database.

Invoking GetRowSetMetaData for MySQLInvoking GetRowSetMetaData for MySQL

Invoking GetRowSetMetaData for Oracle

Figure : shows how to run the solution for the Oracle database.

Invoking GetRowSetMetaData for OracleInvoking GetRowSetMetaData for Oracle

Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

JDBC Topics