文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
ListDatabases
搭配 a AWS SDK 使用
下列程式碼範例示範如何使用 ListDatabases
。
- Java
-
- Java 2.x 的 SDK
-
注意
還有更多 on 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 詳細資訊,請參閱 ListDatabases AWS SDK for Java 2.x 參考中的 API。
-
GetStatementResult
ModifyCluster