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. Use the default TYPE_FORWARD_ONLY to read rows in order. See JDBC statement creation.
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. Use untyped getObject to read a nullable boolean.
getObject(indexOrLabel) returns the natural Java representation of the Prism value. Use the class overload for graph values, lists, and documents. For example, when the result contains a path column named route, read it with rows.getObject("route", PolyPath.class). Use a specific getter or the untyped overload for scalar values. The explicit Map<String, Class<?>> overload is unsupported.
Use getArray() on a JDBC array to read its values as a Java array, or getResultSet() to read one row per entry. The array’s result set contains the one-based position in INDEX and the original value in VALUE. Use getObject("VALUE") to read entries that include graph values or Java null.
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 this cursor’s 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.