Displaying and navigating a result set

There are a variety of ways in which you may want to display the data in a result set produced by a Select bean or ProcedureCall bean. You could use a set of text fields to display all of the columns in a single row, allowing the user to step through all of the rows one at a time. You could use a JTable to display all of the rows and columns in a tabular form. Or you might want to use various interface components to display only a subset of the result data, such as using a list box to display the values of a single column in all of the rows. Convenient ways of displaying such subsets are provided by a set of beans called Selectors

Row-wise Display and navigation of a result set

To display result set data one row at a time, you can make use of two bound properties that VisualAge for Java generates for each data column in the result set when you use the SQL Assist SmartGuide to compose your SQL statement. One property is the data column in its specified data type, another is a String representation of the data column. So, for example, you can make a property-to-property connection between the String representation of a data column in the result set and the text property of a text field. The text field will display the value of the column in the current row of the current result set.

For a ProcedureCall bean, these bound properties are only generated if you use the SQL Assist Smart Guide not only to compose the SQL procedure call statement, but also to describe its result sets. The bound properties only appear in the Visual Composition Editor as connectable features of the ProcedureCall if there is exactly one result set described. (This is appropriate either if the stored procedure returns only one result set, or if all of the result sets it returns have the same column structure.)

Even if the bound properties do not appear as connectable features, you can still listen for the events by making an event-to-code connection between the propertyChange event of the ProcedureCall bean and a method. In the method you can check for properties whose names match the syntax Resultn_columnName or Resultn_columnName_String, where n is the number of a result set and columnName is the name of a column. When one of these names is found, the method can get the new column value from the ProcedureCall bean and set a property of a visual component to display the value.

To display all of the rows in a result set, you will need to step through its rows. You can accomplish this with the DBNavigator bean. Using the DBNavigator bean, you can set the currentRow property of the associated Select or ProcedureCall bean to:

When the current row changes, the values of the bound column properties also change to reflect the values of the new current row. Navigating through the result set changes the value of the data displayed in any interface component connected to the Select bean or ProcedureCall bean. The DBNavigator bean is designed primarily for use with a Select bean or with a ProcedureCall bean that only returns one result set. It does not allow you to change the currentResult property of an associated ProcedureCall bean. If you need to do this, you must incorporate components in your application for doing so, such as a button with an event-to-method connection to the nextResult method of the ProcedureCall bean.

Tabular display and navigation of a result set

To display result set data in tabular form, you can make a property-to-property connection between the this property of a Select bean or ProcedureCall bean and the model property of a JTable. The JTable will display all of the columns in all of the rows in the cache for the current result set.

Many of the Select bean and ProcedureCall bean methods are designed to operate on the current row of the current result set. Since a JTable has its own row selection mechanisms, you will probably wish to use these mechanisms instead of an associated DBNavigator bean to set the currentRow property of a Select or ProcedureCall bean. (However, you may still wish to use a DBNavigator without its navigation buttons to perform operations such as executing the SQL statement, inserting and deleting rows, and committing changes to the database.)

To use the JTable to set the currentRow property of a Select or ProcedureCall bean you must make a property-to-property connection between the selectedRow property of the JTable and the currentRow property of the Select bean or ProcedureCall bean. Because the selectedRow property is not bound, you will also need to specify, in the connection properties, an event such as mouseClicked, to trigger the propagation of the selectedRow value to the currentRow value . This will insure that whenever you select a new row in the JTable, the corresponding row in the Select bean or ProcedureCall bean will become its current row. This is necessary to insure that methods which operate on the current row (such as UpdateRow and DeleteRow) function as expected.

In additon, if you will be using methods of the Select or ProcedureCall bean that change its currentRow property, such as deleteRow, you need to cause the JTable to reflect these changes. To do this, make an event-to-method connection between the currentRow event of your Select bean or ProcedureCall bean and the setRowSelectionInterval method of the JTable.

If you are using the maximumPacketsInCache property of your Select or ProcedureCall bean to limit the number of rows in the cache, the values of currentRow and currentRowInCache may be different. In this case, since the JTable displays the rows in the cache, you should make all of the above connections to the currentRowInCache property instead of the currentRow property.

If you associate a JTable with a ProcedureCall bean that has multiple result sets, the JTable will always display the current result set. To change the currentResult property of the ProcedureCall bean, you must incorporate components in your application for doing so, such as a button with an event-to-method connection to the nextResult method of the ProcedureCall bean.

Related concepts
About Relational Database Access
Related procedures
Connecting beans
Editing Select bean properties
Editing ProcedureCall bean properties
Adding the DBNavigator bean to the Visual Composition Editor surface
Inserting, updating, or deleting data in a result set
Using Selector beans

Related references
Select
ProcedureCall
DBNavigator