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

来源:互联网 发布:外贸薪资 知乎 编辑:程序博客网 时间:2024/05/24 05:10
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));
}
原创粉丝点击