Database Reference
In-Depth Information
Get item
This method allows you to retrieve a stored item from a specified table identified by a
specified primary key. The inputs required to be provided are table name and primary key.
The following is the syntax for this:
//Create key instance for item to be fetched
HashMap<String, AttributeValue> key = new HashMap<String,
AttributeValue>();
key.put("bookId", new AttributeValue().withN("2001"));
// Create get item request
GetItemRequest getItemRequest = new
GetItemRequest().withTableName("Book").withKey(key);
// Call getItem method from DynamoDB client
GetItemResult getItemResult =
dynamoDBClient.getItem(getItemRequest);
You can also provide some additional attributes, such as attributes to fetch, consistency
type (strong/eventual), and so on:
// List of attributes to be fetched
List<String> attributesTobeFetched = new ArrayList<String>(
Arrays.asList("bookId", "name", "isbn", "authors"));
// Create key instance for item to be fetched
HashMap<String, AttributeValue> key = new HashMap<String,
AttributeValue>();
key.put("bookId", new AttributeValue().withN("2001"));
// Create get item request
GetItemRequest getItemRequest = new GetItemRequest()
.withTableName("Book").withKey(key)
.withAttributesToGet(attributesTobeFetched)
.withConsistentRead(true);
// Call getItem method from DynamoDB client
Search WWH ::




Custom Search