Skip to content

Files

Latest commit

f680c9e · Apr 30, 2025

History

History

samples

Getting Started with Cloud Spanner and the Google Cloud Client libraries

Open in Cloud Shell

Cloud Spanner is a horizontally-scalable database-as-a-service with transactions and SQL support. These sample Java applications demonstrate how to access the Spanner API using the Google Cloud Client Library for Java.

Quickstart

Install Maven.

Build your project from the root directory (java-spanner):

mvn clean package -DskipTests
cd samples/snippets
mvn package

Every subsequent command here should be run from a subdirectory samples/snippets.

Running samples

Usage:

java -jar target/spanner-snippets/spanner-google-cloud-samples.jar operation my-instance my-database

Examples

Create Database:

java -jar target/spanner-google-cloud-samples-jar-with-dependencies.jar my-instance my-database

Listing database operations:

java -jar target/spanner-snippets/spanner-google-cloud-samples.jar listdatabaseoperations my-instance my-database