Navigational Actions with ADS and Java

Unlike Delphi and ADO-based ADS applications, which support a wide range of navigational operations, JDBC supports only simple navigation. Specifically, the ResultSet class permits you to navigate forward through the records of the result set, and if the cursor is bidirectional, you can move forward and backward, using methods with names such as first, next, last, and previous. The use of simple forward navigation is demonstrated in the following section.


Some classes in Borland’s DataExpress in JBuilder support additional navigational capabilities, such as filtering. These classes, however, are not native to JDBC.

Scanning a Result Set

Scanning is the process of sequentially reading every record in a result set. Although scanning is a common task, it is important to note that it necessarily requires the client application to retrieve all of the records in the result set. This is not a problem when few records are involved, but if a large number of records are being scanned, network resources may be taxed.


If you must scan a large number of records, implement the operation using an AEP. Scanning from an AEP installed on ADS requires no network resources.

The following code demonstrates scanning. It is associated with the actionPerformed event handler of the List Products button (shown in Figure 13-1), and it navigates the entire PRODUCTS table, assigning data from each record to the ProductList JListBox:

void listProductsBtn_actionPerformed(ActionEvent e) {   DefaultListModel listModel = new javax.swing.DefaultListModel();   try {   ResultSet rs = stmt.executeQuery("SELECT * FROM PRODUCTS");   rs.first();   do {   listModel.addElement(rs.getString(1) + "  " +   rs.getString(2));   } while (;   productList.setModel(listModel);   }   catch (Exception e1) {   System.err.println( e1.getMessage());   } } 

Note that the do-while loop in the preceding event handler could also have been written as follows:

while ( do {   listModel.addElement(rs.getString(1) + "  " +   rs.getString(2)); }

While the behavior of these two control structures is equivalent, there is a potential drawback to the second version, the while-do loop. Specifically, if the ResultSet has been navigated in any way prior to the while-do loop, the first record will be skipped. The do-while statement preceded by a call to the first method, by comparison, always processes every record in the ResultSet, whether or not the ResultSet has been navigated previously.

Advantage Database Server. The Official Guide
Advantage Database Server: The Official Guide
ISBN: 0072230843
EAN: 2147483647
Year: 2002
Pages: 129

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: