Integrate Spanner with IntelliJ

This page describes how to connect to a Spanner database inIntelliJ and other JetBrains products.

IntelliJ IDEA is an integrated development environment fordeveloping software in Java, Kotlin, Groovy, and other JVM-based languages.

This page assumes that you already have IntelliJ or another JetBrains IDEinstalled on your computer.

Connect to Spanner

Connecting IntelliJ to your Spanner database lets you executequeries and other SQL statements on your Spanner databasedirectly from IntelliJ. It also enables code completion and validation for tableand column names in your code.

You can connect to both GoogleSQL-dialect databases and PostgreSQL-dialect databases by following these steps:

  1. In IntelliJ, click the menu optionFile > New > Datasource > GoogleSpanner. TheGoogle Spanner driver is under theOther sub-menu ifyou have not used this driver before.

  2. In the Data Sources window, enter your project, instance, and database ID.

  3. Optional: Select a service account key file if you want to authenticateusing a service account. SelectNo Auth in the Credentials drop-down ifyou want to use your default credentials.Connect toSpanner toolwindow

  4. Click OK to create the data source. The Spanner database isadded to the Database window in IntelliJ.

  5. In the Databases window, expand the data source that you just added. Thenclick the... button next to the textNo schemas selected.

  6. Select the optionAll schemas to instruct IntelliJ to introspect allschemas in the database. IntelliJ will then populate the database view withall tables and views in your database.

    Connect to Spanner toolwindow

Connect to the Spanner Emulator

You can also connect IntelliJ to a database in theSpannerEmulator:

  1. First start the emulator with one of the following commands:

    1. gcloud emulators spanner start
    2. docker run -p 9010:9010 -p 9020:9020gcr.io/cloud-spanner-emulator/emulator
  2. Click the menu optionFile > New > Datasource > Google Spanner. TheGoogle Spanner driver is under theOther sub-menu if you have not usedthis driver before.

  3. Enter the project, instance, and database ID.NOTE: The project,instance and database don't need to exist in the emulator.

  4. SelectNo Auth in the Credentials drop-down.

  5. Click theAdvanced tab in the Data Sources window.

  6. Modify the value ofautoConfigEmulator totrue.

  7. Click OK to accept all changes. The project, instance, and database will becreated on the emulator automatically if these don't exist already.

    Connect to Spanner toolwindow

  8. In the Databases window, expand the data source that you just added. Clickthe... button next to the textNo schemas selected.

  9. Select the optionAll schemas to instruct IntelliJ to introspect allschemas in the database. IntelliJ will then populate the database view withall tables and views in your database.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.