Hi all i got error when i want to insert data to my dynamoDb like this
in my code i have add the Symbol. and here my code
public class InsertData {
static AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://dynamodb.us-east-2.amazonaws.com", "us-east-2"))
.build();
static DynamoDB dynamoDB = new DynamoDB(client);
static String tableName = "PriceOneZero";
public static void main(String[] args)throws IOException {
// TODO Auto-generated method stub
System.out.println("Call CreateItem");
createItems();
}
private static void createItems() {
// TODO Auto-generated method stub
Table table = dynamoDB.getTable(tableName);
System.out.println("runFirstTime For Insert Data");
try{
String symbols= "USDJPY";
String price = "100.89";
String time = "2020-06-05T00:00:02.111";
//Add Content
Item item = new Item().withPrimaryKey("Symbol", symbols).withString("Price", price).withString("Time", time);
//save to DynamoDb
table.putItem(item);
System.out.println("Success For Insert Data");
}catch (AmazonDynamoDBException e) {
System.err.println("Create items failed.");
System.err.println(e.getMessage());
}
}
}
when i use that code in my database there is only have data
Symbol :USDJPY Price : 100.89 Time : 2020-06-05T00:00:02.111
after that i try to change my code become
public class InsertData {
static AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://dynamodb.us-east-2.amazonaws.com", "us-east-2"))
.build();
static DynamoDB dynamoDB = new DynamoDB(client);
static String tableName = "PriceOneZero";
public static void main(String[] args)throws IOException {
// TODO Auto-generated method stub
System.out.println("Call CreateItem");
createItems();
}
private static void createItems() {
// TODO Auto-generated method stub
Table table = dynamoDB.getTable(tableName);
System.out.println("runFirstTime For Insert Data");
try{
String symbols= "USDJPY";
String price = "100.89";
String time = "2020-06-05T00:00:02.112";
//Add Content
Item item = new Item().withPrimaryKey("Symbol", symbols).withString("Price", price).withString("Time", time);
//save to DynamoDb
table.putItem(item);
System.out.println("Success For Insert Data");
}catch (AmazonDynamoDBException e) {
System.err.println("Create items failed.");
System.err.println(e.getMessage());
}
}
}
the diffirent is in Time from .111 become .112
and in my dynamoDb Database my data only like update that not add so i only have one data like Symbol :USDJPY Price : 100.89 Time : 2020-06-05T00:00:02.111
not like this Symbol Price time USDJPY 100.89 2020-06-05T00:00:02.111 USDJPY 100.89 2020-06-05T00:00:02.112
why like that ?
my question why there is any error ? and how to fix it ?
regards,
Fuad