A java.sql.ResultSet is a read-only cursor over relational rows. Call next() before the first read. Column indexes start at 1. Use column labels for name-based access and give ambiguous expressions explicit SQL aliases. Label lookup is case-insensitive.
Move the cursor
| Method | Behavior |
|---|---|
next() |
Advances to the next row. For ordinary forward-only reads, use while (rows.next()). |
getRow() |
Returns the current row number or 0 when the cursor is off a row. |
isBeforeFirst(), isAfterLast(), isFirst(), isLast() |
Inspect local cursor state. The driver uses rows buffered locally for position tests, so use next() to determine whether forward iteration has finished. |
first(), last(), previous() |
Select the first, last or previous row in a scrollable result. Moving to the end can require fetching and buffering the remaining rows. |
beforeFirst(), afterLast() |
Move a scrollable cursor off its current row to a boundary. |
absolute(row), relative(offset) |
Move a scrollable cursor with a one-based absolute position or an offset relative to the current position. Negative absolute positions count from the end. |
Request TYPE_SCROLL_INSENSITIVE when creating the statement to use the scroll operations. In 3.1, scrollable results have edge cases at empty results and cursor boundaries. For predictable full iteration, use the default TYPE_FORWARD_ONLY.
Example: scroll within a nonempty result
First run the Statement setup example.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class ScrollTasks {
public static void main(String[] args) throws Exception {
String url = args.length == 0 ? "jdbc:polypheny://localhost:20590" : args[0];
try (Connection connection = DriverManager.getConnection(url, "pa", "");
Statement statement = connection.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rows = statement.executeQuery(
"SELECT id, title FROM public.jdbc_docs_tasks ORDER BY id")) {
if (rows.absolute(2)) {
System.out.println(rows.getString("title"));
}
if (rows.previous()) {
System.out.println(rows.getInt("id"));
}
}
}
}
Read column values
Choose a getter from the type conversion table. Most getters have both an index and a label overload. findColumn(label) resolves a label to a one-based index. Call wasNull() immediately after a getter to check whether it read SQL NULL. A numeric getter can return zero for NULL. For a nullable boolean, use untyped getObject, since getBoolean can throw for NULL in 3.1.
The polymorphic getObject(indexOrLabel) returns a Java value based on the underlying Prism type. The getObject(indexOrLabel, Class<T>) overload does not convert ordinary scalar values in 3.1. Prefer a specific getter or cast the result of untyped getObject. The explicit Map<String, Class<?>> overload is unsupported.
Fetch and close
| Method | Behavior |
|---|---|
getMetaData() |
Returns column metadata for this result. |
getStatement() |
Returns the statement that produced the result. Metadata results have no producing statement. |
setFetchSize(rows), getFetchSize() |
Adjust or read the fetch hint for subsequent frames. The initial frame may already have arrived. |
setFetchDirection(direction), getFetchDirection() |
Set or read the fetch direction hint. Use FETCH_FORWARD for forward-only results. |
getType(), getConcurrency(), getHoldability() |
Report the cursor type, concurrency and holdability. |
close(), isClosed() |
Close the result and check whether it is closed. |
getWarnings(), clearWarnings() |
The driver does not track result-set warnings. getWarnings() returns null. |
getCursorName() |
Unsupported. |
isWrapperFor(type), unwrap(type) |
Check or obtain the compatible driver implementation. |
Unsupported Features
Result sets are read-only. The update* setters, insertRow, updateRow, deleteRow, refreshRow, cancelRowUpdates, moveToInsertRow and moveToCurrentRow cannot change result-set data. rowUpdated, rowInserted and rowDeleted are unsupported. Execute SQL with a Statement or PreparedStatement to modify data.
| Updater family | Unsupported methods in all overloads |
|---|---|
| Null, scalar, and temporal values | updateNull, updateBoolean, updateByte, updateShort, updateInt, updateLong, updateFloat, updateDouble, updateBigDecimal, updateString, updateBytes, updateDate, updateTime, updateTimestamp, updateNString |
| Streams | updateAsciiStream, updateBinaryStream, updateCharacterStream, updateNCharacterStream |
| LOB and other values | updateObject, updateRef, updateBlob, updateClob, updateArray, updateRowId, updateNClob, updateSQLXML |
The concrete Polypheny result set also exposes fetchAll() to request buffering of remaining rows.