Provides access to the data returned by a Cloud Spanner read or query. ResultSet allows a
single row to be inspected at a time through the methods from the StructReader interface,
in the order that the rows were returned by the read or query. The result set can be positioned
over the next row, if one exists, by calling #next(); this method returns false
when all rows returned have been seen. The result set is initially positioned before the first
row, so a call to next() is required before the first row can be inspected.
ResultSet implementations may buffer data ahead and/or maintain a persistent streaming
connection to the remote service until all data has been returned or the resultSet closed. As
such, it is important that all uses of ResultSet either fully consume it (that is, call
next() until false is returned or it throws an exception) or explicitly call
#close(): failure to do so may result in wasted work or leaked resources.
ResultSet implementations are not required to be thread-safe: if methods are called
from multiple threads, external synchronization must be used.
Explicitly close the result set, releasing any associated resources. This must always be called
when disposing of a ResultSet before #next() has returned false or
raised an exception. Calling close() is also allowed if the result set has been fully
consumed, so a recommended practice is to unconditionally close the result set once it is done
with, typically using a try-with-resources construct.
getCurrentRowAsStruct()
publicabstractStructgetCurrentRowAsStruct()
Creates an immutable version of the row that the result set is positioned over. This may
involve copying internal data structures, and so converting all rows to Struct objects
is generally more expensive than processing the ResultSet directly.
Returns the ResultSetStats for the query only if the query was executed in either the
PLAN or the PROFILE mode via the ReadContext#analyzeQuery(Statement,
com.google.cloud.spanner.ReadContext.QueryAnalyzeMode) method or for DML statements in ReadContext#executeQuery(Statement, QueryOption...). Attempts to call this method on a
ResultSet not obtained from analyzeQuery or executeQuery will return a
nullResultSetStats. This method must be called after #next() has
returned @{code false}. Calling it before that will result in null
ResultSetStats too.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Interface ResultSet (6.98.1)\n\nVersion latestkeyboard_arrow_down\n\n- [6.98.1 (latest)](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet)\n- [6.98.0](/java/docs/reference/google-cloud-spanner/6.98.0/com.google.cloud.spanner.ResultSet)\n- [6.97.1](/java/docs/reference/google-cloud-spanner/6.97.1/com.google.cloud.spanner.ResultSet)\n- [6.96.1](/java/docs/reference/google-cloud-spanner/6.96.1/com.google.cloud.spanner.ResultSet)\n- [6.95.1](/java/docs/reference/google-cloud-spanner/6.95.1/com.google.cloud.spanner.ResultSet)\n- [6.94.0](/java/docs/reference/google-cloud-spanner/6.94.0/com.google.cloud.spanner.ResultSet)\n- [6.93.0](/java/docs/reference/google-cloud-spanner/6.93.0/com.google.cloud.spanner.ResultSet)\n- [6.89.0](/java/docs/reference/google-cloud-spanner/6.89.0/com.google.cloud.spanner.ResultSet)\n- [6.88.0](/java/docs/reference/google-cloud-spanner/6.88.0/com.google.cloud.spanner.ResultSet)\n- [6.87.0](/java/docs/reference/google-cloud-spanner/6.87.0/com.google.cloud.spanner.ResultSet)\n- [6.86.0](/java/docs/reference/google-cloud-spanner/6.86.0/com.google.cloud.spanner.ResultSet)\n- [6.85.0](/java/docs/reference/google-cloud-spanner/6.85.0/com.google.cloud.spanner.ResultSet)\n- [6.83.0](/java/docs/reference/google-cloud-spanner/6.83.0/com.google.cloud.spanner.ResultSet)\n- [6.82.0](/java/docs/reference/google-cloud-spanner/6.82.0/com.google.cloud.spanner.ResultSet)\n- [6.80.1](/java/docs/reference/google-cloud-spanner/6.80.1/com.google.cloud.spanner.ResultSet)\n- [6.79.0](/java/docs/reference/google-cloud-spanner/6.79.0/com.google.cloud.spanner.ResultSet)\n- [6.77.0](/java/docs/reference/google-cloud-spanner/6.77.0/com.google.cloud.spanner.ResultSet)\n- [6.74.1](/java/docs/reference/google-cloud-spanner/6.74.1/com.google.cloud.spanner.ResultSet)\n- [6.72.0](/java/docs/reference/google-cloud-spanner/6.72.0/com.google.cloud.spanner.ResultSet)\n- [6.71.0](/java/docs/reference/google-cloud-spanner/6.71.0/com.google.cloud.spanner.ResultSet)\n- [6.69.0](/java/docs/reference/google-cloud-spanner/6.69.0/com.google.cloud.spanner.ResultSet)\n- [6.68.0](/java/docs/reference/google-cloud-spanner/6.68.0/com.google.cloud.spanner.ResultSet)\n- [6.66.0](/java/docs/reference/google-cloud-spanner/6.66.0/com.google.cloud.spanner.ResultSet)\n- [6.65.1](/java/docs/reference/google-cloud-spanner/6.65.1/com.google.cloud.spanner.ResultSet)\n- [6.62.0](/java/docs/reference/google-cloud-spanner/6.62.0/com.google.cloud.spanner.ResultSet)\n- [6.60.0](/java/docs/reference/google-cloud-spanner/6.60.0/com.google.cloud.spanner.ResultSet)\n- [6.58.0](/java/docs/reference/google-cloud-spanner/6.58.0/com.google.cloud.spanner.ResultSet)\n- [6.57.0](/java/docs/reference/google-cloud-spanner/6.57.0/com.google.cloud.spanner.ResultSet)\n- [6.56.0](/java/docs/reference/google-cloud-spanner/6.56.0/com.google.cloud.spanner.ResultSet)\n- [6.55.0](/java/docs/reference/google-cloud-spanner/6.55.0/com.google.cloud.spanner.ResultSet)\n- [6.54.0](/java/docs/reference/google-cloud-spanner/6.54.0/com.google.cloud.spanner.ResultSet)\n- [6.53.0](/java/docs/reference/google-cloud-spanner/6.53.0/com.google.cloud.spanner.ResultSet)\n- [6.52.1](/java/docs/reference/google-cloud-spanner/6.52.1/com.google.cloud.spanner.ResultSet)\n- [6.51.0](/java/docs/reference/google-cloud-spanner/6.51.0/com.google.cloud.spanner.ResultSet)\n- [6.50.1](/java/docs/reference/google-cloud-spanner/6.50.1/com.google.cloud.spanner.ResultSet)\n- [6.49.0](/java/docs/reference/google-cloud-spanner/6.49.0/com.google.cloud.spanner.ResultSet)\n- [6.25.1](/java/docs/reference/google-cloud-spanner/6.25.1/com.google.cloud.spanner.ResultSet)\n- [6.24.0](/java/docs/reference/google-cloud-spanner/6.24.0/com.google.cloud.spanner.ResultSet)\n- [6.23.4](/java/docs/reference/google-cloud-spanner/6.23.4/com.google.cloud.spanner.ResultSet)\n- [6.22.0](/java/docs/reference/google-cloud-spanner/6.22.0/com.google.cloud.spanner.ResultSet)\n- [6.21.2](/java/docs/reference/google-cloud-spanner/6.21.2/com.google.cloud.spanner.ResultSet)\n- [6.20.0](/java/docs/reference/google-cloud-spanner/6.20.0/com.google.cloud.spanner.ResultSet)\n- [6.19.1](/java/docs/reference/google-cloud-spanner/6.19.1/com.google.cloud.spanner.ResultSet)\n- [6.18.0](/java/docs/reference/google-cloud-spanner/6.18.0/com.google.cloud.spanner.ResultSet)\n- [6.17.4](/java/docs/reference/google-cloud-spanner/6.17.4/com.google.cloud.spanner.ResultSet)\n- [6.14.1](/java/docs/reference/google-cloud-spanner/6.14.1/com.google.cloud.spanner.ResultSet) \n\n public interface ResultSet extends AutoCloseable, StructReader\n\nProvides access to the data returned by a Cloud Spanner read or query. `ResultSet` allows a\nsingle row to be inspected at a time through the methods from the [StructReader](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.StructReader) interface,\nin the order that the rows were returned by the read or query. The result set can be positioned\nover the next row, if one exists, by calling [#next()](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet#com_google_cloud_spanner_ResultSet_next__); this method returns `false`\nwhen all rows returned have been seen. The result set is initially positioned before the first\nrow, so a call to `next()` is required before the first row can be inspected.\n\n`ResultSet` implementations may buffer data ahead and/or maintain a persistent streaming\nconnection to the remote service until all data has been returned or the resultSet closed. As\nsuch, it is important that all uses of `ResultSet` either fully consume it (that is, call\n`next()` until `false` is returned or it throws an exception) or explicitly call\n[#close()](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet#com_google_cloud_spanner_ResultSet_close__): failure to do so may result in wasted work or leaked resources.\n\n`ResultSet` implementations are not required to be thread-safe: if methods are called\nfrom multiple threads, external synchronization must be used. \n\nImplements\n----------\n\n[AutoCloseable](https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html), [StructReader](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.StructReader)\n\nMethods\n-------\n\n### close()\n\n public abstract void close()\n\nExplicitly close the result set, releasing any associated resources. This must always be called\nwhen disposing of a `ResultSet` before [#next()](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet#com_google_cloud_spanner_ResultSet_next__) has returned `false` or\nraised an exception. Calling `close()` is also allowed if the result set has been fully\nconsumed, so a recommended practice is to unconditionally close the result set once it is done\nwith, typically using a try-with-resources construct.\n\n### getCurrentRowAsStruct()\n\n public abstract Struct getCurrentRowAsStruct()\n\nCreates an immutable version of the row that the result set is positioned over. This may\ninvolve copying internal data structures, and so converting all rows to `Struct` objects\nis generally more expensive than processing the `ResultSet` directly.\n\n### getMetadata()\n\n public default ResultSetMetadata getMetadata()\n\nReturns the [ResultSetMetadata](/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.ResultSetMetadata) for this [ResultSet](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet). This is method may only be\ncalled after calling [ResultSet#next()](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet#com_google_cloud_spanner_ResultSet_next__) at least once.\n\n### getStats()\n\n public abstract ResultSetStats getStats()\n\nReturns the [ResultSetStats](/java/docs/reference/google-cloud-spanner/latest/com.google.spanner.v1.ResultSetStats) for the query only if the query was executed in either the\n`PLAN` or the `PROFILE` mode via the ReadContext#analyzeQuery(Statement, com.google.cloud.spanner.ReadContext.QueryAnalyzeMode) method or for DML statements in [ReadContext#executeQuery(Statement, QueryOption...)](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ReadContext#com_google_cloud_spanner_ReadContext_executeQuery_). Attempts to call this method on a `\nResultSet` not obtained from `analyzeQuery` or `executeQuery` will return a `\nnull` `ResultSetStats`. This method must be called after [#next()](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ResultSet#com_google_cloud_spanner_ResultSet_next__) has\nreturned @{code false}. Calling it before that will result in `null` `\nResultSetStats` too.\n\n### next()\n\n public abstract boolean next()\n\nAdvances the result set to the next row, returning false if no such row exists. This method may\nblock."]]