您的位置:首页 > 编程语言 > Java开发

java客户端通过get方法获取Hbase的数据

2017-08-16 09:07 459 查看
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"));

table.close();
System.out.println(result.toString());
System.out.println(Bytes.toString(value));
System.out.println(Bytes.toString(value1));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐