java - 为什么当我更改我喜欢的价格和时间时,我的 dynamoDb 喜欢更新而不添加新的?
问题描述
大家好,当我想像这样将数据插入到我的 dynamoDb 时出现错误
在我的代码中,我添加了符号。这里是我的代码
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());
}
}
}
当我在我的数据库中使用该代码时,只有数据
交易品种:USDJPY 价格:100.89 时间:2020-06-05T00:00:02.111
之后我尝试将我的代码更改为
公共类插入数据 {
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());
}
}
}
不同的时间是从 .111 变成 .112
在我的 dynamoDb 数据库中,我的数据只喜欢更新而不添加,所以我只有一个数据,比如 Symbol :USDJPY 价格:100.89 时间:2020-06-05T00:00:02.111
不喜欢这个 符号 价格时间 USDJPY 100.89 2020-06-05T00:00:02.111 USDJPY 100.89 2020-06-05T00:00:02.112
为什么这样?
我的问题为什么有任何错误?以及如何解决?
问候,
福阿德
解决方案
推荐阅读
- python-3.x - 如何指定函数的函数的参数类型
- python - 根据命令行参数运行 pytest 标记
- android - 无法将 Android AAR(带有 JNI 绑定)与 Jitpack 上的源关联
- excel - 如何使用 VBA 进行 Excel 循环
- ubuntu - 如何在 .awk 脚本中编写多个命令?
- php - 如何在 PHP 中为 SQLite3 启用预写日志?
- javascript - Bcrypt比较问题nodejs
- reactjs - 来自下一个/图像的 400 错误请求
- python - 命令“where python”在 PowerShell 中不返回任何内容
- mysql - mysql为nextjs项目创建连接或池