An interface for Cloud Spanner. Typically, there would only be one instance of this for the
lifetime of the application which must be closed by invoking #close() when it is no
longer needed. Failure to do so may result in leaking session resources and exhausting session
quota.
Closes all the clients associated with this instance and frees up all the resources. This
method will block until it can clean up all the resources. Specifically, it deletes all the
underlying sessions (which involves rpcs) and closes all the gRPC channels. Once this method
called, this object is no longer usable. It is strongly advised to call this method when you
are done with the Spanner object, typically when your application shuts down. There is
a hard limit on number of sessions in Cloud Spanner and not calling this method can lead to
unused sessions piling up on the backend.
Returns a BatchClient to do batch operations on Cloud Spanner databases. Batch client
is useful when one wants to read/query a large amount of data from Cloud Spanner across
multiple processes, even across different machines. It allows to create partitions of Cloud
Spanner database and then read/query over each partition independently yet at the same
snapshot.
For all other use cases, DatabaseClient is more appropriate and performant.
[[["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 Spanner (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.Spanner)\n- [6.98.0](/java/docs/reference/google-cloud-spanner/6.98.0/com.google.cloud.spanner.Spanner)\n- [6.97.1](/java/docs/reference/google-cloud-spanner/6.97.1/com.google.cloud.spanner.Spanner)\n- [6.96.1](/java/docs/reference/google-cloud-spanner/6.96.1/com.google.cloud.spanner.Spanner)\n- [6.95.1](/java/docs/reference/google-cloud-spanner/6.95.1/com.google.cloud.spanner.Spanner)\n- [6.94.0](/java/docs/reference/google-cloud-spanner/6.94.0/com.google.cloud.spanner.Spanner)\n- [6.93.0](/java/docs/reference/google-cloud-spanner/6.93.0/com.google.cloud.spanner.Spanner)\n- [6.89.0](/java/docs/reference/google-cloud-spanner/6.89.0/com.google.cloud.spanner.Spanner)\n- [6.88.0](/java/docs/reference/google-cloud-spanner/6.88.0/com.google.cloud.spanner.Spanner)\n- [6.87.0](/java/docs/reference/google-cloud-spanner/6.87.0/com.google.cloud.spanner.Spanner)\n- [6.86.0](/java/docs/reference/google-cloud-spanner/6.86.0/com.google.cloud.spanner.Spanner)\n- [6.85.0](/java/docs/reference/google-cloud-spanner/6.85.0/com.google.cloud.spanner.Spanner)\n- [6.83.0](/java/docs/reference/google-cloud-spanner/6.83.0/com.google.cloud.spanner.Spanner)\n- [6.82.0](/java/docs/reference/google-cloud-spanner/6.82.0/com.google.cloud.spanner.Spanner)\n- [6.80.1](/java/docs/reference/google-cloud-spanner/6.80.1/com.google.cloud.spanner.Spanner)\n- [6.79.0](/java/docs/reference/google-cloud-spanner/6.79.0/com.google.cloud.spanner.Spanner)\n- [6.77.0](/java/docs/reference/google-cloud-spanner/6.77.0/com.google.cloud.spanner.Spanner)\n- [6.74.1](/java/docs/reference/google-cloud-spanner/6.74.1/com.google.cloud.spanner.Spanner)\n- [6.72.0](/java/docs/reference/google-cloud-spanner/6.72.0/com.google.cloud.spanner.Spanner)\n- [6.71.0](/java/docs/reference/google-cloud-spanner/6.71.0/com.google.cloud.spanner.Spanner)\n- [6.69.0](/java/docs/reference/google-cloud-spanner/6.69.0/com.google.cloud.spanner.Spanner)\n- [6.68.0](/java/docs/reference/google-cloud-spanner/6.68.0/com.google.cloud.spanner.Spanner)\n- [6.66.0](/java/docs/reference/google-cloud-spanner/6.66.0/com.google.cloud.spanner.Spanner)\n- [6.65.1](/java/docs/reference/google-cloud-spanner/6.65.1/com.google.cloud.spanner.Spanner)\n- [6.62.0](/java/docs/reference/google-cloud-spanner/6.62.0/com.google.cloud.spanner.Spanner)\n- [6.60.0](/java/docs/reference/google-cloud-spanner/6.60.0/com.google.cloud.spanner.Spanner)\n- [6.58.0](/java/docs/reference/google-cloud-spanner/6.58.0/com.google.cloud.spanner.Spanner)\n- [6.57.0](/java/docs/reference/google-cloud-spanner/6.57.0/com.google.cloud.spanner.Spanner)\n- [6.56.0](/java/docs/reference/google-cloud-spanner/6.56.0/com.google.cloud.spanner.Spanner)\n- [6.55.0](/java/docs/reference/google-cloud-spanner/6.55.0/com.google.cloud.spanner.Spanner)\n- [6.54.0](/java/docs/reference/google-cloud-spanner/6.54.0/com.google.cloud.spanner.Spanner)\n- [6.53.0](/java/docs/reference/google-cloud-spanner/6.53.0/com.google.cloud.spanner.Spanner)\n- [6.52.1](/java/docs/reference/google-cloud-spanner/6.52.1/com.google.cloud.spanner.Spanner)\n- [6.51.0](/java/docs/reference/google-cloud-spanner/6.51.0/com.google.cloud.spanner.Spanner)\n- [6.50.1](/java/docs/reference/google-cloud-spanner/6.50.1/com.google.cloud.spanner.Spanner)\n- [6.49.0](/java/docs/reference/google-cloud-spanner/6.49.0/com.google.cloud.spanner.Spanner)\n- [6.25.1](/java/docs/reference/google-cloud-spanner/6.25.1/com.google.cloud.spanner.Spanner)\n- [6.24.0](/java/docs/reference/google-cloud-spanner/6.24.0/com.google.cloud.spanner.Spanner)\n- [6.23.4](/java/docs/reference/google-cloud-spanner/6.23.4/com.google.cloud.spanner.Spanner)\n- [6.22.0](/java/docs/reference/google-cloud-spanner/6.22.0/com.google.cloud.spanner.Spanner)\n- [6.21.2](/java/docs/reference/google-cloud-spanner/6.21.2/com.google.cloud.spanner.Spanner)\n- [6.20.0](/java/docs/reference/google-cloud-spanner/6.20.0/com.google.cloud.spanner.Spanner)\n- [6.19.1](/java/docs/reference/google-cloud-spanner/6.19.1/com.google.cloud.spanner.Spanner)\n- [6.18.0](/java/docs/reference/google-cloud-spanner/6.18.0/com.google.cloud.spanner.Spanner)\n- [6.17.4](/java/docs/reference/google-cloud-spanner/6.17.4/com.google.cloud.spanner.Spanner)\n- [6.14.1](/java/docs/reference/google-cloud-spanner/6.14.1/com.google.cloud.spanner.Spanner) \n\n public interface Spanner extends Service\u003cSpannerOptions\u003e, AutoCloseable\n\nAn interface for Cloud Spanner. Typically, there would only be one instance of this for the\nlifetime of the application which must be closed by invoking [#close()](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Spanner#com_google_cloud_spanner_Spanner_close__) when it is no\nlonger needed. Failure to do so may result in leaking session resources and exhausting session\nquota. \n\nImplements\n----------\n\ncom.google.cloud.Service\\\u003ccom.google.cloud.spanner.SpannerOptions\\\u003e, [AutoCloseable](https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html)\n\nMethods\n-------\n\n### close()\n\n public abstract void close()\n\nCloses all the clients associated with this instance and frees up all the resources. This\nmethod will block until it can clean up all the resources. Specifically, it deletes all the\nunderlying sessions (which involves rpcs) and closes all the gRPC channels. Once this method\ncalled, this object is no longer usable. It is strongly advised to call this method when you\nare done with the `Spanner` object, typically when your application shuts down. There is\na hard limit on number of sessions in Cloud Spanner and not calling this method can lead to\nunused sessions piling up on the backend.\n\n### createDatabaseAdminClient()\n\n public default DatabaseAdminClient createDatabaseAdminClient()\n\nReturns a [com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient) to execute\nadmin operations on Cloud Spanner databases. This method always creates a new instance of\n[com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient) which is an [AutoCloseable](https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html) resource. For optimising the number of clients, caller may choose to cache the\nclients instead of repeatedly invoking this method and creating new instances.\n\n### createInstanceAdminClient()\n\n public default InstanceAdminClient createInstanceAdminClient()\n\nReturns a [com.google.cloud.spanner.admin.instance.v1.InstanceAdminClient](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.admin.instance.v1.InstanceAdminClient) to execute\nadmin operations on Cloud Spanner databases. This method always creates a new instance of\n[com.google.cloud.spanner.admin.instance.v1.InstanceAdminClient](/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.admin.instance.v1.InstanceAdminClient) which is an [AutoCloseable](https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html) resource. For optimising the number of clients, caller may choose to cache the\nclients instead of repeatedly invoking this method and creating new instances.\n\n### getAsyncExecutorProvider()\n\n public abstract ExecutorProvider getAsyncExecutorProvider()\n\n### getBatchClient(DatabaseId db)\n\n public abstract BatchClient getBatchClient(DatabaseId db)\n\nReturns a `BatchClient` to do batch operations on Cloud Spanner databases. Batch client\nis useful when one wants to read/query a large amount of data from Cloud Spanner across\nmultiple processes, even across different machines. It allows to create partitions of Cloud\nSpanner database and then read/query over each partition independently yet at the same\nsnapshot.\n\nFor all other use cases, `DatabaseClient` is more appropriate and performant. \n\n\n SpannerOptions options = SpannerOptions.newBuilder().build();\n Spanner spanner = options.getService();\n final String project = \"test-project\";\n final String instance = \"test-instance\";\n final String database = \"example-db\";\n DatabaseId db =\n DatabaseId.of(project, instance, database);\n BatchClient batchClient = spanner.getBatchClient(db);\n \n### getDatabaseAdminClient()\n\n public abstract DatabaseAdminClient getDatabaseAdminClient()\n\nReturns a `DatabaseAdminClient` to execute admin operations on Cloud Spanner databases.\n\n### getDatabaseClient(DatabaseId db)\n\n public abstract DatabaseClient getDatabaseClient(DatabaseId db)\n\nReturns a `DatabaseClient` for the given database. It uses a pool of sessions to talk to\nthe database. \n\n\n SpannerOptions options = SpannerOptions.newBuilder().build();\n Spanner spanner = options.getService();\n final String project = \"test-project\";\n final String instance = \"test-instance\";\n final String database = \"example-db\";\n DatabaseId db =\n DatabaseId.of(project, instance, database);\n DatabaseClient dbClient = spanner.getDatabaseClient(db);\n \n### getInstanceAdminClient()\n\n public abstract InstanceAdminClient getInstanceAdminClient()\n\nReturns an `InstanceAdminClient` to execute admin operations on Cloud Spanner instances.\n\n### isClosed()\n\n public abstract boolean isClosed()"]]