13 hbase连接

时间:2021-06-16 09:55:46
 Configuration conf=new Configuration();
String zookeeper="";
String clientport="";
String tableName="pbtest";
String rowkey="";
conf.set(HBASE_ZOOKEEPER_QUORUM, zookeeper);
conf.set(HBASE_ZOOKEEPER_CLINETPORT, clientport);
conf= HBaseConfiguration.create(conf); Table table=null;
try {
Connection connection = ConnectionFactory.createConnection(conf);
table=connection.getTable(TableName.valueOf(tableName));
} catch (IOException e) {
e.printStackTrace();
}
Get get=new Get(Bytes.toBytes(rowkey));
Result result= null;
try {
result = table.get(get);
} catch (IOException e) {
e.printStackTrace();
}
Cell cell = result.getColumnLatestCell(Bytes.toBytes("cf"), Bytes.toBytes("data"));
byte[] value = CellUtil.cloneValue(cell);