java客户端获取Hbase单行数据或多行数据示例
来源:互联网 发布:mac上无法连接itunes 编辑:程序博客网 时间:2024/06/16 18:30
public static void main(String[] args) throws MasterNotRunningException, IOException{
// TODO Auto-generated method stub
String tableName = "zrl_emp";
//配置对象
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.master", "hdfs://Master.Hadoop:60000");
conf.set("hbase.rootdir", "hdfs://Master.Hadoop:9000/hbase");
conf.set("hbase.zookeeper.property.clientPort", "2181");
conf.set("hbase.zookeeper.quorum", "Master.Hadoop,Slave1.Hadoop");
//连接对象
Connection conn = ConnectionFactory.createConnection(conf);
Table table = conn.getTable(TableName.valueOf(tableName));
//查询单行数据
Get g = new Get(Bytes.toBytes("rowKey1"));
Result result = table.get(g);
byte [] value = result.getValue(Bytes.toBytes("personal data"),
Bytes.toBytes("newColumnName2"));
byte[] value1 = result.getValue(Bytes.toBytes("personal data"),
Bytes.toBytes("city"));
//查询多行数据
List<Get> gets = new ArrayList<Get>();
Get get2 = new Get(Bytes.toBytes("rowKey2"));
Get get3 = new Get(Bytes.toBytes("rowKey3"));
Get get4 = new Get(Bytes.toBytes("rowKey4"));
gets.add(get2);
gets.add(get3);
gets.add(get4);
Result[] results = table.get(gets);
table.close();
System.out.println(result.toString());
System.out.println(result.size());
System.out.println(result.rawCells());
System.out.println(Bytes.toString(value));
System.out.println(Bytes.toString(value1));
System.out.println("--------------------");
for (int i = 0; i < results.length; i++) {
byte [] value2 = results[i].getValue(Bytes.toBytes("personal data"),
Bytes.toBytes("newColumnName2"));
System.out.println(Bytes.toString(value2));
}
}
// TODO Auto-generated method stub
String tableName = "zrl_emp";
//配置对象
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.master", "hdfs://Master.Hadoop:60000");
conf.set("hbase.rootdir", "hdfs://Master.Hadoop:9000/hbase");
conf.set("hbase.zookeeper.property.clientPort", "2181");
conf.set("hbase.zookeeper.quorum", "Master.Hadoop,Slave1.Hadoop");
//连接对象
Connection conn = ConnectionFactory.createConnection(conf);
Table table = conn.getTable(TableName.valueOf(tableName));
//查询单行数据
Get g = new Get(Bytes.toBytes("rowKey1"));
Result result = table.get(g);
byte [] value = result.getValue(Bytes.toBytes("personal data"),
Bytes.toBytes("newColumnName2"));
byte[] value1 = result.getValue(Bytes.toBytes("personal data"),
Bytes.toBytes("city"));
//查询多行数据
List<Get> gets = new ArrayList<Get>();
Get get2 = new Get(Bytes.toBytes("rowKey2"));
Get get3 = new Get(Bytes.toBytes("rowKey3"));
Get get4 = new Get(Bytes.toBytes("rowKey4"));
gets.add(get2);
gets.add(get3);
gets.add(get4);
Result[] results = table.get(gets);
table.close();
System.out.println(result.toString());
System.out.println(result.size());
System.out.println(result.rawCells());
System.out.println(Bytes.toString(value));
System.out.println(Bytes.toString(value1));
System.out.println("--------------------");
for (int i = 0; i < results.length; i++) {
byte [] value2 = results[i].getValue(Bytes.toBytes("personal data"),
Bytes.toBytes("newColumnName2"));
System.out.println(Bytes.toString(value2));
}
}
阅读全文
0 0
- java客户端获取Hbase单行数据或多行数据示例
- Hbase Java客户端示例
- java客户端通过get方法获取Hbase的数据
- 获取数据行数据信息
- jqGrid 使用示例&获取选中行数据
- HBase java 统计表行数
- java 获取 hbase数据 springdatahadoop -- hbasetemplate
- java 获取 hbase数据 springdatahadoop -- hbasetemplate
- HBase--Java访问HBase示例
- 数据由单列或单行编辑成多行多列
- Linq中行数据已更改或行数据已删除
- 更新、插入tableview某一行数据或section数据
- HBase Java简单示例
- HBase Java简单示例
- HBase Java简单示例
- HBase Java简单示例
- HBase Java简单示例
- HBase Java编程示例
- [python笔记]完善describe()
- 【kubernetes/k8s 部署】minikube 与 kubernetes 源码单机搭建
- 面试OR笔试7——小孩分蛋糕
- A
- 年度收官之作:SDCC 2017中国软件开发者大会 北京站来啦!
- java客户端获取Hbase单行数据或多行数据示例
- FastJson
- url传参——GetRequest函数修复
- [python笔记]行列转换,数据透视
- Android app去掉标题栏
- linux AWK 内置函数split,substr用法
- hdu1224
- xcode模拟器调试输入密码问题
- 如何打开远程服务器的任务管理器