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 ...
随机推荐
- mysql 不允许分组的问题
异常信息:this is incompatible with sql_mode=only_full_group_by 解决办法: 找到 my.cnf find / -name my.cnf 然后在 ...
- bzoj 2739 最远点——分治处理决策单调性
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2739 分治处理决策单调性的思想就是先找到一个询问,枚举所有可能的转移找到它的决策点,那么这个 ...
- php上传导入文件 nginx-502错误
4. php程序执行时间过长而超时,检查nginx和fastcgi中各种timeout设置.(nginx 中的 fastcgi_connect_timeout 300;fastcgi_send_ti ...
- SSM的配置文件
Mybatis: SqlMapConfig.xml,配置了数据源,连接池,事务,加载sql映射文件(pojo),sqlsessionFactory对象,配置到spring容器中,mapeer代理对象或 ...
- flume http source示例讲解
一.介绍 flume自带的Http Source可以通过Http Post接收事件. 场景:对于有些应用程序环境,它可能不能部署Flume SDK及其依赖项,或客户端代码倾向于通过HTTP而不是Flu ...
- IDC:时钟系统
ylbtech-IDC:时钟系统 主要应用于要求有统一时间进行生产,调度的单位如:电力,机场.轻轨.地铁.体育场馆.酒店.医院.部队.油田.水利工程等领域.大区域时钟系统主要由母钟和多台子钟构成. 1 ...
- 学习笔记之Data analysis
Data analysis - Wikipedia https://en.wikipedia.org/wiki/Data_analysis Data analysis is a process of ...
- 学习笔记之pandas Foundations | DataCamp
pandas Foundations | DataCamp https://www.datacamp.com/courses/pandas-foundations Many real-world da ...
- python图片和字符串的转换
有个业务,需要将图片压缩转化为64位编码上传到服务端. import json,requests,base64 #网上下载图片素材 r = requests.get("https://tim ...
- 认识hasLayout——IE浏览器css bug的一大罪恶根源
原文地址:http://neverned.blog.163.com/blog/static/1265524200933021130561/ 什么是hasLayout?hasLayout是IE特有 ...