Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questa pagina descrive come connettersi a un database Spanner in IntelliJ e in altri prodotti JetBrains.
IntelliJ IDEA è un ambiente di sviluppo integrato per lo sviluppo di software in Java, Kotlin, Groovy e altri linguaggi basati su JVM.
Questa pagina presuppone che tu abbia già installato IntelliJ o un altro IDE JetBrains sul tuo computer.
Connettiti a Spanner
La connessione di IntelliJ al tuo database Spanner ti consente di eseguire query
e altre istruzioni SQL sul tuo database Spanner direttamente da
IntelliJ. Inoltre, consente il completamento e la convalida del codice per i nomi di tabelle e colonne nel codice.
Per connetterti ai database in dialetto GoogleSQL e PostgreSQL, segui questi passaggi:
In IntelliJ, fai clic sull'opzione di menu
File > New > Datasource > Google Spanner.
Il driver Google Spanner si trova nel sottomenu Other se non lo hai mai utilizzato.
Nella finestra Origini dati, inserisci l'ID progetto, l'istanza e il database.
(Facoltativo) Seleziona un file della chiave dell'account di servizio se vuoi autenticarti utilizzando un account di servizio. Seleziona No Auth nel menu a discesa Credenziali se vuoi utilizzare le tue credenziali predefinite.
Fai clic su OK per creare l'origine dati. Il database Spanner viene aggiunto alla finestra Database in IntelliJ.
Nella finestra Database, espandi l'origine dati appena aggiunta. Quindi,
fai clic sul pulsante ... accanto al testo No schemas selected.
Seleziona l'opzione All schemas per indicare a IntelliJ di eseguire l'introspezione di tutti gli schemi nel database. IntelliJ completerà quindi la vista del database con tutte le tabelle e le viste del database.
Per prima cosa, avvia l'emulatore con uno dei seguenti comandi:
gcloud emulators spanner start
docker run -p 9010:9010 -p 9020:9020 gcr.io/cloud-spanner-emulator/emulator
Fai clic sull'opzione di menu File > New > Datasource > Google Spanner.
Il driver Google Spanner si trova nel sottomenu Other se non lo hai mai utilizzato.
Inserisci l'ID progetto, istanza e database. NOTA: il progetto, l'istanza e il database non devono necessariamente esistere nell'emulatore.
Seleziona No Auth nel menu a discesa Credenziali.
Fai clic sulla scheda Advanced nella finestra Origini dati.
Modifica il valore di autoConfigEmulator in true.
Fai clic su OK per accettare tutte le modifiche. Se non esistono già, il progetto, l'istanza e il database verranno creati automaticamente nell'emulatore.
Nella finestra Database, espandi l'origine dati appena aggiunta.
Fai clic sul pulsante ... accanto al testo No schemas selected.
Seleziona l'opzione All schemas per indicare a IntelliJ di eseguire l'introspezione di tutti gli schemi nel database. IntelliJ completerà quindi la vista del database con tutte le tabelle e le viste del database.
Passaggi successivi
Per ulteriori informazioni su come aggiungere e utilizzare le origini dati in IntelliJ, consulta Origini dati di IntelliJ.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-08-17 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)."]]