Processing Result Sets
Positioning Within a Result Set
A ResultSet object contains a cursor that points to its current data row. Initially, the cursor is positioned before the first row. The next method moves the cursor to the following row. Since this method returns false when there are no further rows in the ResultSet object, it can be utilized within a while loop to iterate through the result set. However, for scrollable result sets, the JDBC driver offers additional positioning methods to direct the ResultSet to specific rows. These positioning methods are outlined in Table 1.
Method |
Description |
---|---|
next() |
Advances the ResultSet by one row. |
previous() |
Retreats the ResultSet by one row. |
beforeFirst() |
Positions the ResultSet before the first row. |
afterLast() |
Places the ResultSet after the last row. |
first() |
Directs the ResultSet to the first row. |
last() |
Navigates the ResultSet to the last row. |
absolute(int) |
Relocates the ResultSet to the row number specified by the parameter. |
Obtaining the Cursor Position in the Result Set
For scrollable result sets, positioning methods might be invoked to alter the cursor's location. The JDBC driver supplies methods to ascertain the cursor's position within a result set. Methods for determining the cursor's position are detailed in Table 2.
Obtaining Data in a Result Set
The ResultSet object provides an array of methods to extract data from a result set. Commonly used methods for data retrieval are listed in Table 3, with additional methods available in the JDK official documentation.
Method |
Description |
---|---|
int getInt(int columnIndex) |
Retrieves integer data by column index. |
int getInt(String columnLabel) |
Retrieves integer data by column label. |
String getString(int columnIndex) |
Retrieves string data by column index. |
String getString(String columnLabel) |
Retrieves string data by column label. |
Date getDate(int columnIndex) |
Retrieves date data by column index. |
Date getDate(String columnLabel) |
Retrieves date data by column label. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot