Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Auf dieser Seite wird beschrieben, wie Sie in IntelliJ und anderen JetBrains-Produkten eine Verbindung zu einer Spanner-Datenbank herstellen.
IntelliJ IDEA ist eine integrierte Entwicklungsumgebung für die Entwicklung von Software in Java, Kotlin, Groovy und anderen JVM-basierten Sprachen.
Auf dieser Seite wird davon ausgegangen, dass Sie bereits IntelliJ oder eine andere JetBrains-IDE auf Ihrem Computer installiert haben.
Verbindung zu Cloud Spanner herstellen
Wenn Sie IntelliJ mit Ihrer Spanner-Datenbank verbinden, können Sie Abfragen und andere SQL-Anweisungen direkt in IntelliJ in Ihrer Spanner-Datenbank ausführen. Außerdem werden Codevervollständigung und Validierung für Tabellen- und Spaltennamen in Ihrem Code aktiviert.
So stellen Sie eine Verbindung zu Datenbanken mit GoogleSQL- und PostgreSQL-Dialekt her:
Klicken Sie in IntelliJ auf das Dreipunkt-Menü File > New > Datasource > Google Spanner.
Wenn Sie diesen Treiber noch nicht verwendet haben, finden Sie ihn im Untermenü Other.Google Spanner
Geben Sie im Fenster „Datenquellen“ Ihr Projekt, Ihre Instanz und die Datenbank-ID ein.
Optional: Wählen Sie eine Dienstkontoschlüsseldatei aus, wenn Sie sich mit einem Dienstkonto authentifizieren möchten. Wählen Sie im Drop-down-Menü „Anmeldedaten“ die Option No Auth aus, wenn Sie Ihre Standardanmeldedaten verwenden möchten.
Klicken Sie auf „OK“, um die Datenquelle zu erstellen. Die Spanner-Datenbank wird dem Datenbankfenster in IntelliJ hinzugefügt.
Maximieren Sie im Fenster „Datenbanken“ die Datenquelle, die Sie gerade hinzugefügt haben. Klicken Sie dann auf die Schaltfläche ... neben dem Text No schemas selected.
Wählen Sie die Option All schemas aus, um IntelliJ anzuweisen, alle Schemas in der Datenbank zu untersuchen. IntelliJ füllt dann die Datenbankansicht mit allen Tabellen und Ansichten in Ihrer Datenbank.
Verbindung zum Spanner-Emulator herstellen
Sie können IntelliJ auch mit einer Datenbank im Spanner-Emulator verbinden:
Starten Sie zuerst den Emulator mit einem der folgenden Befehle:
gcloud emulators spanner start
docker run -p 9010:9010 -p 9020:9020 gcr.io/cloud-spanner-emulator/emulator
Klicke auf die Menüoption File > New > Datasource > Google Spanner.
Wenn Sie diesen Treiber noch nicht verwendet haben, finden Sie ihn im Untermenü Other.Google Spanner
Geben Sie die Projekt-, Instanz- und Datenbank-ID ein. HINWEIS: Das Projekt, die Instanz und die Datenbank müssen nicht im Emulator vorhanden sein.
Wählen Sie im Drop-down-Menü „Anmeldedaten“ die Option No Auth aus.
Klicken Sie im Fenster „Datenquellen“ auf den Tab Advanced.
Ändern Sie den Wert von autoConfigEmulator in true.
Klicken Sie auf „OK“, um alle Änderungen zu akzeptieren. Das Projekt, die Instanz und die Datenbank werden automatisch im Emulator erstellt, falls sie noch nicht vorhanden sind.
Maximieren Sie im Fenster „Datenbanken“ die Datenquelle, die Sie gerade hinzugefügt haben.
Klicken Sie auf die Schaltfläche ... neben dem Text No schemas selected.
Wählen Sie die Option All schemas aus, um IntelliJ anzuweisen, alle Schemas in der Datenbank zu untersuchen. IntelliJ füllt dann die Datenbankansicht mit allen Tabellen und Ansichten in Ihrer Datenbank.
Nächste Schritte
Weitere Informationen zum Hinzufügen und Verwenden von Datenquellen in IntelliJ finden Sie unter IntelliJ-Datenquellen.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-05 (UTC)."],[],[],null,["# Integrate Spanner with IntelliJ\n\nThis page describes how to connect to a Spanner database in IntelliJ and\nother JetBrains products.\n\n[IntelliJ IDEA](https://www.jetbrains.com/idea/) is an integrated development environment\nfor developing software in Java, Kotlin, Groovy, and other JVM-based languages.\n\nThis page assumes that you already have IntelliJ or another JetBrains IDE\ninstalled on your computer.\n\nConnect to Spanner\n------------------\n\nConnecting IntelliJ to your Spanner database lets you execute queries\nand other SQL statements on your Spanner database directly from\nIntelliJ. It also enables code completion and validation for table and column\nnames in your code.\n\nYou can connect to both GoogleSQL-dialect databases and PostgreSQL-dialect databases by following these steps:\n\n1. In IntelliJ, click the menu option\n `File \u003e New \u003e Datasource \u003e Google Spanner`.\n The `Google Spanner` driver is under the `Other` sub-menu if you have\n not used this driver before.\n\n2. In the Data Sources window, enter your project, instance, and database ID.\n\n3. Optional: Select a service account key file if you want to authenticate using\n a service account. Select `No Auth` in the Credentials drop-down if you want\n to use your default credentials.\n\n4. Click OK to create the data source. The Spanner database is\n added to the Database window in IntelliJ.\n\n5. In the Databases window, expand the data source that you just added. Then\n click the `...` button next to the text `No schemas selected`.\n\n6. Select the option `All schemas` to instruct IntelliJ to introspect all\n schemas in the database. IntelliJ will then populate the database view with\n all tables and views in your database.\n\nConnect to the Spanner Emulator\n-------------------------------\n\nYou can also connect IntelliJ to a database in the\n[Spanner Emulator](https://cloud.google.com/spanner/docs/emulator):\n\n1. First start the emulator with one of the following commands:\n\n 1. `gcloud emulators spanner start`\n 2. `docker run -p 9010:9010 -p 9020:9020 gcr.io/cloud-spanner-emulator/emulator`\n2. Click the menu option `File \u003e New \u003e Datasource \u003e Google Spanner`.\n The `Google Spanner` driver is under the `Other` sub-menu if you have\n not used this driver before.\n\n3. Enter the project, instance, and database ID. **NOTE**: The project, instance\n and database do not need to exist in the emulator.\n\n4. Select `No Auth` in the Credentials drop-down.\n\n5. Click the `Advanced` tab in the Data Sources window.\n\n6. Modify the value of `autoConfigEmulator` to `true`.\n\n7. Click OK to accept all changes. The project, instance, and database will\n be created on the emulator automatically if these do not exist already.\n\n8. In the Databases window, expand the data source that you just added.\n Click the `...` button next to the text `No schemas selected`.\n\n9. Select the option `All schemas` to instruct IntelliJ to introspect all\n schemas in the database. IntelliJ will then populate the database view with\n all tables and views in your database.\n\nWhat's next\n-----------\n\n- For more documentation on how to add and work with data sources in IntelliJ, visit [IntelliJ Data sources](https://www.jetbrains.com/help/idea/managing-data-sources.html).\n- Learn more about the [Spanner Emulator](https://cloud.google.com/spanner/docs/emulator)."]]