Package io.github.connellite.jdbc
Class ResultSetStringIterator
java.lang.Object
io.github.connellite.jdbc.AbstractResultSetIterator<String>
io.github.connellite.jdbc.ResultSetStringIterator
- All Implemented Interfaces:
AutoCloseable,Iterator<Map<String,String>>
Forward-only iterator over JDBC query rows.
Use
AbstractResultSetIterator.asIterable() for for (Map<String, String> row : ...) together with try-with-resources;
the cursor is single-pass, so a second loop on the same instance will not replay rows from the start.
Closing releases the result set and statement from construction.
-
Field Summary
Fields inherited from class io.github.connellite.jdbc.AbstractResultSetIterator
columnNames, hasNextValue, resultSet -
Constructor Summary
ConstructorsConstructorDescriptionExecutes a boundNamedPreparedStatement; all named parameters must be bound before use.ResultSetStringIterator(Connection conn, String query, Object... params) Executesqueryand iterates resulting rows asMap<String, String>.ResultSetStringIterator(ResultSet resultSet) Wraps an already openedResultSet. -
Method Summary
Modifier and TypeMethodDescriptionReads all rows into an immutable list.getAll(Connection conn, String query, Object... params) Reads all rows into an immutable list.Reads all rows from an existingResultSetinto an immutable list.Reads the first row, if present.getFirst(Connection conn, String query, Object... params) Reads the first row, if present.Reads the first row from an existingResultSet, if present.next()Returns the current row as a column-to-value map (stringified values) and advances cursor.Methods inherited from class io.github.connellite.jdbc.AbstractResultSetIterator
asIterable, close, hasNextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Constructor Details
-
ResultSetStringIterator
Executesqueryand iterates resulting rows asMap<String, String>.- Throws:
SQLException
-
ResultSetStringIterator
Executes a boundNamedPreparedStatement; all named parameters must be bound before use.- Throws:
SQLException
-
ResultSetStringIterator
Wraps an already openedResultSet.- Throws:
SQLException
-
-
Method Details
-
next
Returns the current row as a column-to-value map (stringified values) and advances cursor. -
getAll
public static List<Map<String,String>> getAll(Connection conn, String query, Object... params) throws SQLException Reads all rows into an immutable list.- Throws:
SQLException
-
getAll
Reads all rows into an immutable list.- Throws:
SQLException
-
getFirst
public static Optional<Map<String,String>> getFirst(Connection conn, String query, Object... params) throws SQLException Reads the first row, if present.- Throws:
SQLException
-
getFirst
Reads the first row, if present.- Throws:
SQLException
-
getAll
Reads all rows from an existingResultSetinto an immutable list.- Throws:
SQLException
-
getFirst
Reads the first row from an existingResultSet, if present.- Throws:
SQLException
-