在dynamodb

时间:2017-10-26 04:06:25

标签: java amazon-web-services insert

这是我在DynamoDb管理器类中的方法,它可以轻松上传DynamoDB表中的值。这个方法工作正常,就是它将数据插入到表中,但问题是每次它被某个按钮活动调用时,它都会重写先前插入的值而不是插入新值。 如果有人可以帮助我,那就太棒了!

public static ArrayList<UserUpdBuks> uploadNewBooks(){
    AmazonDynamoDBClient ddb = NavigationDrawerActivity.clientManager
            .ddb();
    DynamoDBMapper mapper = new DynamoDBMapper(ddb);

    try{
            for(int i=1; i<=5; i++) {
                UserUpdBuks up = new UserUpdBuks();
                up.setAuthor(Upload_BookDetailsPage.uBookAuthor);
                up.setBook_Name(Upload_BookDetailsPage.uBookName);
                Log.d(TAG, "Uploading New Book");
                mapper.save(up);
                Log.d(TAG, "Book Uploaded !");

            }
    }catch (AmazonServiceException ex) {
        Log.e(TAG, "Error inserting users");
        NavigationDrawerActivity.clientManager
                .wipeCredentialsOnAuthError(ex);
    }

    return null;
}

这是我调用上述方法的其他类的一部分:

this.textViewBookName= (TextView) 
findViewById(R.id.valueUploadBookName);
this.textViewBookName.setText(product.getName());

this.textViewBookAuthor= (TextView) 
findViewById(R.id.valueUploadBookAuthor);
this.textViewBookAuthor.setText(product.getAuthor());

uBookName = product.getName();
uBookAuthor = product.getAuthor();

clientManager = new AmazonClientManager(this);

final Button uploadNewBttn = (Button) findViewById(R.id.uploadButton);
uploadNewBttn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            Log.i("Upload_BookDetailsPage", "Submit button clicked.");

            new GetBookListTask().execute();
        }
    });

2 个答案:

答案 0 :(得分:0)

我希望allcabs.get()Upload_BookDetailsPage.uBookAuthor静态值,这些值在代码或for循环中永远不会更改。

Upload_BookDetailsPage.uBookName

答案 1 :(得分:0)

解决了它,基本上它缺少主键插入值,因此它重写了相同的值。