1

我是 iOS 和 AWS 的新手...

我一直在尝试从 AWS 上的 SDB 中检索数据……

首先,我想连接到 aws,然后我想从 somedomain 中检索所有内容并将其放入数组中。并读出数组内部的内容。

 // Connecting to SDB    
 AmazonSimpleDBClient *sdbClient = [[AmazonSimpleDBClient alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY];


@try {
    SimpleDBSelectRequest *selectRequest = [[SimpleDBSelectRequest alloc] initWithSelectExpression:@"select * from somedomain"];
    selectRequest.consistentRead = YES;
    if (self.nextToken != nil) {
        selectRequest.nextToken = self.nextToken;
    }

    SimpleDBSelectResponse *selectResponse = [sdbClient select:selectRequest];
    self.nextToken = selectResponse.nextToken;

    NSLog(self.nextToken);

}
@catch (NSException *exception) {
    NSLog(@"Exception : [%@]", exception);

}

提前谢谢你们。我感谢所有的帮助。:)

4

1 回答 1

2

这里有一些帮助在 java 中列出域、创建域、添加属性、删除属性和列出项目。

public boolean checkSubscriptionToAmazonSimpleDB(String accessKey, String secretKey) {
            try {
                basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey);
                amazonSimpleDBClient = new AmazonSimpleDBClient(basicAWSCredentials);
                String sNextToken = "";
                boolean bDomainExist = false;
                do {
                    ListDomainsRequest listDomainsRequest = new ListDomainsRequest();
                    listDomainsRequest.setMaxNumberOfDomains(100);
                    listDomainsRequest.setNextToken(sNextToken);
                    ListDomainsResult listDomainsResult = amazonSimpleDBClient.listDomains(listDomainsRequest);
                    sNextToken = listDomainsResult.getNextToken();
                    List<String> list = listDomainsResult.getDomainNames();
                    for (String domain : list) {
                        System.out.println(domain);
                    }
                } while (sNextToken != null && bDomainExist == false);

            } catch (Throwable ex) {
                System.out.println(ex.toString());
                return false;
            }
            return true;
        }

        public void createDomain(String domain) {
            CreateDomainRequest createDomainRequest = new CreateDomainRequest(domain);
            amazonSimpleDBClient.createDomain(createDomainRequest);

        }

        private boolean addItem(String domain, String itemName) {
            try {
                PutAttributesRequest putAttributesRequest = new PutAttributesRequest();
                putAttributesRequest.setDomainName(domain);
                putAttributesRequest.setItemName(itemName);
                List<ReplaceableAttribute> list = new ArrayList<ReplaceableAttribute>();
                list.add(new ReplaceableAttribute("A", "a", true));
                list.add(new ReplaceableAttribute("B", "c", true));
                list.add(new ReplaceableAttribute("C", "b", true));
                putAttributesRequest.setAttributes(list);
                amazonSimpleDBClient.putAttributes(putAttributesRequest);
            } catch (Throwable ex) {
                System.out.println(ex.toString());
                return false;
            }
            return true;
        }

        private boolean deleteItem(String domain, String itemName) {
            try {
                DeleteAttributesRequest deleteAttributesRequest = new DeleteAttributesRequest();
                deleteAttributesRequest.setDomainName(domain);
                deleteAttributesRequest.setItemName(itemName);
                amazonSimpleDBClient.deleteAttributes(deleteAttributesRequest);
            } catch (Throwable ex) {
                System.out.println(ex.toString());
                return false;
            }
            return true;
        }

        public void getListOfArchived(String domainname, String pagesize, String nextToken) {
            SelectResult selectResult = null;
            String sNextToken = null;
            String query = null;
            do {
                query = "select * from " + domainname;
                SelectRequest selectRequest = new SelectRequest(query);
                selectRequest.setNextToken(nextToken);
                selectResult = amazonSimpleDBClient.select(selectRequest);
                sNextToken = selectResult.getNextToken();
                List<Item> list = selectResult.getItems();
                for(Item item: list){
                    item.getName(); // itemName
                    List<Attribute> listAttribute = item.getAttributes();
                    for(Attribute attribute:listAttribute){
                        attribute.getName(); // Attribute Name
                        attribute.getValue(); // Attribute value;
                    }
                }
            } while (sNextToken != null);

        }
于 2012-09-03T05:44:47.157 回答