TableStore:创建SyncClient+getRow读取一行数据
1、通过控制台或者客户端,在TableStore中新建了实例owlforest,在实例详情中获取到实例访问地址endPoint

2、新建表user,确定主键为userid(Interger)类型,因为TableStore最多支持4个主键,这里先尝试一个主键的情况。
3、通过控制台新增数据

4、修改pom.xml
<dependency>
<groupId>com.aliyun.openservices</groupId>
<artifactId>tablestore</artifactId>
<version>4.10.2</version>
</dependency>
5、通过主键,用getRow获取一行数据(使用默认配置创建 SyncClient)
package com.aliyun.demo.controller;
import com.alicloud.openservices.tablestore.SyncClient;
import com.alicloud.openservices.tablestore.model.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class Tablestore {
final String endPoint = "实例访问地址";
final String accessKeyId = "accessKeyId";
final String accessKeySecret = "accessKeySecret";
final String instanceName = "实例名";
@RequestMapping("/query")
public String query() {
SyncClient client = new SyncClient(endPoint, accessKeyId, accessKeySecret, instanceName);
GetRowRequest rowRequest = new GetRowRequest();
SingleRowQueryCriteria queryCriteria = new SingleRowQueryCriteria("user");
//读取数据时,返回的最多版本个数。
queryCriteria.setMaxVersions(5);
//主键
PrimaryKeyBuilder primaryKeyBuilder = PrimaryKeyBuilder.createPrimaryKeyBuilder();
primaryKeyBuilder.addPrimaryKeyColumn("userid", PrimaryKeyValue.fromLong(2));
queryCriteria.setPrimaryKey(primaryKeyBuilder.build());
rowRequest.setRowQueryCriteria(queryCriteria);
GetRowResponse rowResponse = client.getRow(rowRequest);
if(rowResponse == null){
return "未获取到TableStore的数据";
}else{
String responseMsg = "";
Column[] cols = rowResponse.getRow().getColumns();
for (Column col : cols){
System.out.println(col.getName());
System.out.println(col.getValue());
responseMsg = responseMsg + "Name:" + col.getName() + ",Value:" + col.getValue() + ", ";
}
return responseMsg;
}
}
}
采用自定义配置的方式创建SyncClient
ClientConfiguration clientConfiguration = new ClientConfiguration(); // 设置建立连接的超时时间。 clientConfiguration.setConnectionTimeoutInMillisecond(5000); // 设置socket超时时间。 clientConfiguration.setSocketTimeoutInMillisecond(5000); // 设置重试策略,若不设置,采用默认的重试策略。 clientConfiguration.setRetryStrategy(new AlwaysRetryStrategy()); // 其他配置项省略 SyncClient client = new SyncClient(endPoint, accessKeyId, accessKeySecret, instanceName, clientConfiguration);
6、结果

TableStore:创建SyncClient+getRow读取一行数据的更多相关文章
- c++从文件中读取一行数据并保存在数组中
从txt文本中读取数据存入数组中 #include <iostream> #include <fstream> #include <string> #include ...
- xml读取一行数据
#include<map>#include<iostream>#include<fstream>#include<string>using namesp ...
- C/C++程序从文本文件中读取(保存)数据
:本文仅供初学者参阅,解惑 在C程序中: 与程序代码外的数据(文件)打交道,我们使用到流(stream)这个概念,实现进程的虚拟内存与文件之间的数据交换. ——文件流:C标准库提供了FILE(之所以命 ...
- 【转】fscanf 跳过空格,读取一行
fscanf(fp, "%s", sLineWord); 以上语句,在读取一行数据时,如何遇到该行数据有空格,那么读到空格处就停止,不再继续向下读. 若想遇到空格继续读取,读取完整 ...
- Python读取文件数据
1题目要求: 文本文件有这些数据,需要的只有其中的5个属性,如下颜色标记 像以下的数据达到75万组: 1product/productId: B0000UIXZ4 2product/title: Ti ...
- 在MVC中动态读取JSON数据创建表格
//使用getJSON // ("@Url.Action("GetAllUsers","User")" ,json文件的路径.也可以是 /M ...
- jxl读写excel, poi读写excel,word, 读取Excel数据到MySQL
这篇blog是介绍: 1. java中的poi技术读取Excel数据,然后保存到MySQL数据中. 2. jxl读写excel 你也可以在 : java的poi技术读取和导入Excel了解到写入Exc ...
- Java读取Excel数据
Java读取Excel数据,解析文本并格式化输出 Java读取Excel数据,解析文本并格式化输出 Java读取Excel数据,解析文本并格式化输出 下图是excel文件的路径和文件名 下图是exce ...
- poi——读取excel数据
单元格类型 读取Excel数据 package com.java.test.poi; import java.io.File; import java.io.FileInputStream; impo ...
随机推荐
- Linux下vim基本操作和清空文件内容的常用方法
以前都是用的很土的办法,大概有以下几种.1.直接删除,创建一个新的同名文件(这种方法的弊端是有可能这个文件带着权限或者是属性,那么你新建这个文件后有可能会导致权限不正确或者丢失属性).2.使用vim编 ...
- python连接Mongo数据库
python连接Mongo数据库主要采用pymongo连接,一般情况分为两种连接方式,一种通过指定端口和地址直接连接,另一种通过uri的格式连接 1.通过指定端口和地址连接Mongo conn = M ...
- bzoj 4349 最小树形图——朱刘算法
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4349. 学习博客:http://www.cnblogs.com/xzxl/p/7243466 ...
- java byte数组与String的相互转换
String -> byte数组 String str = "abc天"; byte[] btr = str.getBytes(); System.out.printl ...
- operator笔记
# operator.itemgetter(*items) # 获取item >>> from operator import itemgetter # list使用下标进行返回 & ...
- 如何在linux服务器上使用hanlp
关于如何在linux服务器上使用hanlp也有分享过一篇,但分享的内容与湘笑的这篇还是不同的.此处分享一下湘笑的这篇hanlp在linux服务器上使用的文章,供新手朋友学习之用. 本文主要工作是在li ...
- Hystrix 使用入门
在很多系统架构中都需要考虑横向扩.单点故障等问题,对于一个庞大的应用集群,部分服务或者机器出现问题不可避免,在出现故障时,如何减少故障的影响.保障集群的高可用,成为一个重要的工作,Hystrix 是一 ...
- CI 数据库操作总结
最简单示例 $query = $this->db->query("YOUR QUERY"); foreach ($query->result() as $row) ...
- python 类继承与子类实例初始化
From: https://blog.csdn.net/cs0301lm/article/details/6002504?utm_source=blogxgwz4 [ 先贴参考书籍原文(中文英文对照) ...
- 关于JAVA架构师
在我们行业内,我们大致把程序员分为四级 1.初级Java程序员的重心在编写代码.运用框架: 2.中级Java程序员重心在编写代码和框架: 3.高级Java程序员技术攻关.性能调优: 4.架构师 解决业 ...