|
[Exercise | API Docs | Short Course| Exercises] Help is available for each task. Task 1In doConnect() after connecting, get the DatabaseMetaData in dbmd; create a scrollable ResultSet using ResultSet.TYPE_SCROLL_INSENSITIVE and ResultSet.CONCUR_READ_ONLY; to ensure that the ResultSet does not inadvertently become unavailable, add code to turn off autocommit.
Task 2In doRetrieval(), using the rsMetaData ResultSet, get Primary Key information for sTable and append it to the JTextArea jtaMD; close the ResultSet.
Task 3In doRetrieval(), add code to execute the query, using sQuery, sTable and sOrderBy, retrieving the ResultSet rsScroll; determine that at least one row was returned. If not, inform the user, close rsScroll and return to the display; determine the scroll type. If ResultSet.TYPE_FORWARD_ONLY, close everything, inform the user that the program can not proceed and return to the display.
Task 4In doRetrieval(), add code to get ResultSetMetadata using rsmd and display Catalog, Schema and Table names. -- After this code is a large amount of formatting code using ResultSetMetadata, which is worth the reader's time for a brief review.
Task 5In doNext(), add code to determine whether the "Prev" button should be enabled/disabled and also set the page tracker bHasPrevPage; get and load iPAGE_SIZE rows; add code to determine whether the "Next" button should be enabled/disabled and also set the page tracker bHasNextPage; ensure the proper cursor positioning for the next page request.
Task 6In doPrev(), insert code to set the cursor properly for the next set. The suggested code is explained in detail in the help section and should be reviewed.
If bHasNextPage is false, then the last page is displayed. There can be two conditions: a full page or less than a full page. If the page was full, go back iSET_PREV rows. If there was less than a full page, go back by ( iPAGE_SIZE + the number of rows on the page ) rows. If bHasNextPage is true, then the position can be any other page, including the first. In general, for this condition, the line rsScroll.relative( -(iSET_PREV) ); should handle things properly. However, Cloudscape has apparently implemented ResultSet.relative() to calculate an absolute row number and then invoke ResultSet.absolute(). Sometimes the row number is zero, at which point an SQLException is thrown, and the ResultSet is closed. To avoid this situation, the calculations resulting in the invocation of ResultSet.beforeFirst() are performed, using getRow(). So, you might ask, why not use this calculation all of the time? Well, not every driver always returns a row when ResultSet.getRow() is called. In fact the API allows a zero return and DB2, and very specifically DB2/400, frequently returns zero. Therefore the else code, which works in that case. Given this situation, the code will not work if a driver implements ResultSet.relative() to hand off ( possibly a zero ) to ResultSet.absolute() and does not return a row number on a ResultSet.getRow() call. Copyright 1996-2000 jGuru.com. All Rights Reserved. | ||||||||||||||||
|
| ||||||||||||