Amazon Redshift 將不再支援從修補程式 198 開始建立新的 Python UDFs。現有 Python UDF 將繼續正常運作至 2026 年 6 月 30 日。如需詳細資訊,請參閱部落格文章
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
ListDatabases 搭配 AWS SDK 使用
下列程式碼範例示範如何使用 ListDatabases。
- .NET
-
- 適用於 .NET 的 SDK (v4)
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 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; } }-
如需 API 詳細資訊,請參閱《適用於 .NET 的 AWS SDK API 參考》中的 ListDatabases。
-
- Java
-
- SDK for Java 2.x
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 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); }); }-
如需 API 詳細資訊,請參閱《AWS SDK for Java 2.x API 參考》中的 ListDatabases。
-
- SAP ABAP
-
- 適用於 SAP ABAP 的開發套件
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 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.-
如需 API 詳細資訊,請參閱《適用於 AWS SAP ABAP 的 SDK API 參考》中的 ListDatabases。
-
如需 AWS SDK 開發人員指南和程式碼範例的完整清單,請參閱 透過 AWS SDK 使用此服務。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。
GetStatementResult
ModifyCluster