通过Get获取指定的的字段
package org.common;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
public class Demo5 {
public static void main(String[] args) {
try {
/**
* HBaseAdmin is special class
* some step
*/
//1.get Configuration
Configuration conf = HBaseConfiguration.create();
//2.get connection from Configuration
Connection connection = ConnectionFactory.createConnection(conf);
//3.get HTable from connection
TableName tableName = TableName.valueOf(Bytes.toBytes("emp"));
HTable hTable = (HTable)connection.getTable(tableName);
//4.Construct a Get and put it to hTable
Get get1 = new Get(Bytes.toBytes("row1"));
//get1.addFamily(Bytes.toBytes("personal data")); //get1.addColumn(Bytes.toBytes("personal data"),Bytes.toBytes("name"));
//5.conform Family
//get1.addFamily(Bytes.toBytes("personal data"));
Result result = hTable.get(get1);
byte[] value = result.getValue(Bytes.toBytes("personal data"),Bytes.toBytes("name"));
System.out.println("name:"+Bytes.toString(value));
hTable.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}