ListDatabases搭配使用 AWS SDK - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

ListDatabases搭配使用 AWS SDK

以下代码示例演示如何使用 ListDatabases

Java
SDK适用于 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” 中的。