View a markdown version of this page

Usare ListDatabases con un AWS SDK - Amazon Redshift

Amazon Redshift non supporterà più l'uso delle UDF Python dopo il 30 giugno 2026. Inizieremo ad applicarlo gradualmente. Per ulteriori informazioni sui dettagli della fine del ciclo di vita e sulle opzioni di migrazione di Python, consulta la post sul blog che è stato pubblicato il 30 giugno 2025.

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Usare ListDatabases con un AWS SDK

I seguenti esempi di codice mostrano come usare ListDatabases.

.NET
SDK per .NET (v4)
Nota

C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

/// <summary> /// List databases in a Redshift cluster. /// </summary> /// <param name="clusterIdentifier">The cluster identifier.</param> /// <param name="dbUser">The database user.</param> /// <param name="dbUser">The database name for authentication.</param> /// <returns>A list of database names.</returns> public async Task<List<string>> ListDatabasesAsync(string clusterIdentifier, string dbUser, string databaseName) { try { var request = new ListDatabasesRequest { ClusterIdentifier = clusterIdentifier, DbUser = dbUser, Database = databaseName }; var response = await _redshiftDataClient.ListDatabasesAsync(request); var databases = new List<string>(); foreach (var database in response.Databases) { Console.WriteLine($"The database name is : {database}"); databases.Add(database); } return databases; } catch (Amazon.RedshiftDataAPIService.Model.ValidationException ex) { Console.WriteLine($"Validation error: {ex.Message}"); throw; } catch (Exception ex) { Console.WriteLine($"Couldn't list databases. Here's why: {ex.Message}"); throw; } }
  • Per i dettagli sull'API, consulta ListDatabases nel AWS SDK per .NET Riferimento API.

Java
SDK per Java 2.x
Nota

C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

/** * Lists all databases asynchronously for the specified cluster, database user, and database. * @param clusterId the identifier of the cluster to list databases for * @param dbUser the database user to use for the list databases request * @param database the database to list databases for * @return a {@link CompletableFuture} that completes when the database listing is complete, or throws a {@link RuntimeException} if there was an error */ public CompletableFuture<Void> listAllDatabasesAsync(String clusterId, String dbUser, String database) { ListDatabasesRequest databasesRequest = ListDatabasesRequest.builder() .clusterIdentifier(clusterId) .dbUser(dbUser) .database(database) .build(); // Asynchronous paginator for listing databases. ListDatabasesPublisher databasesPaginator = getAsyncDataClient().listDatabasesPaginator(databasesRequest); CompletableFuture<Void> future = databasesPaginator.subscribe(response -> { response.databases().forEach(db -> { logger.info("The database name is {} ", db); }); }); // Return the future for asynchronous handling. return future.exceptionally(exception -> { throw new RuntimeException("Failed to list databases: " + exception.getMessage(), exception); }); }
  • Per i dettagli sull'API, consulta ListDatabases nel AWS SDK for Java 2.x Riferimento API.

SAP ABAP
SDK per SAP ABAP
Nota

C'è di più su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel repository di esempi di codice AWS.

TRY. " Example values: iv_cluster_identifier = 'redshift-cluster-movies' " Example values: iv_database_name = 'dev' " Example values: iv_database_user = 'awsuser' oo_result = lo_rsd->listdatabases( iv_clusteridentifier = iv_cluster_identifier iv_database = iv_database_name iv_dbuser = iv_database_user ). lt_databases = oo_result->get_databases( ). lv_db_count = lines( lt_databases ). MESSAGE |Retrieved { lv_db_count } database(s).| TYPE 'I'. CATCH /aws1/cx_rsddatabaseconnex. MESSAGE 'Database connection error.' TYPE 'I'. CATCH /aws1/cx_rsdresourcenotfoundex. MESSAGE 'Cluster not found.' TYPE 'I'. ENDTRY.
  • Per i dettagli sull'API, consulta ListDatabases nel AWS Riferimento all'API SDK per SAP ABAP.

Per un elenco completo di AWS Guide per sviluppatori SDK ed esempi di codice, consulta Utilizzo di questo servizio con un AWS SDK. Questo argomento include anche informazioni su come iniziare e dettagli sulle versioni precedenti dell’SDK.