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 ...
随机推荐
- redis 学习资料
redis 学习资料 网址 Redis 教程(菜鸟教程) http://www.runoob.com/redis/redis-tutorial.html Redis 命令参考 http://redis ...
- Spring 4 中重定向RedirectAttributes的使用
RedirectAttributes 的使用 @RequestMapping(value = "/redirecttest", produces = "applicati ...
- Ubuntu Nginx Ruby, Rails Mysql 安装
1. Nginx 安装 sudo apt-get install nginx 2. Ruby 安装 sudo apt-get install ruby 查看版本 ruby -v 3. Rails 安装 ...
- gcc系强制链接静态库(同时有.so和.a)
1. 坑多的办法 -static 如果需要链接成不依赖任何so文件的程序,用ldd查看显示为"not a dynamic executable",但是这个选项时不推荐的. 即使像这 ...
- The Best KPIs to Use in Your Company
Here is a list of key performance indicators (KPIs) that should be used in contact centres, alongsid ...
- Excel技巧--时尚的圆环比例图
如上图,制作方法如下: 1.创建圆环图:选择表格,点击“插入”-->点击 圆环图. 2.删除图中的标题和标记,将圆环内径缩至最小: 3.复制表格的数据,重复两次粘贴到图表中: 4.依次选择内两环 ...
- Python Flask 构建微电影视频网站
前言 学完本教程,你将掌握: 1.学会使用整形.浮点型.路径型.字符串型正则表达式路由转化器 2.学会使用post与get请求.上传文件.cookie获取与相应.404处理 3.学会适应模板自动转义. ...
- C#实现设置系统时间
using System; using System.Runtime.InteropServices; using System.Windows.Forms; namespace Demo { pub ...
- 【转】[Android] NDK独立编译——独立工具链
转载地址:https://blog.csdn.net/suningning/article/details/74510125
- 安装node.msi 格式的文件失败
in10 安装node.msi格式的文件,出现2503 2502 错误码, win+x 打开 在命令提示符窗口中输入: msiexec /package "安装msi格式的文件的全路径&qu ...