標籤:hbase
ubuntu14.04,eclipse下操作hbase。下面是一個利用hbase java api操作hbase,查看hbase中表student1列族情況的example:
import java.io.IOException;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.hadoop.hbase.HColumnDescriptor;import org.apache.hadoop.hbase.HTableDescriptor;import org.apache.hadoop.hbase.client.HBaseAdmin;import org.apache.hadoop.hbase.util.Bytes;public class OperateTable { public static void main(String[] args) throws IOException { Configuration conf = HBaseConfiguration.create(); conf.set("hbase.zookeeper.quorum", "localhost");//使用eclipse時必須添加這個,否則無法定位.後一個參數寫地址,我這裡是偽分布的,所以為localhost conf.set("hbase.zookeeper.property.clientPort", "2181"); HBaseAdmin admin = new HBaseAdmin(conf);// 建立一個資料庫管理員 HTableDescriptor tableDescriptor = admin.getTableDescriptor(Bytes.toBytes("student1")); byte[] name = tableDescriptor.getName(); System.out.println("result:"); System.out.println("table name: "+ new String(name)); HColumnDescriptor[] columnFamilies = tableDescriptor .getColumnFamilies(); for(HColumnDescriptor d : columnFamilies){ System.out.println("column Families: "+ d.getNameAsString()); } }}
[Hbase]eclipse下操作hbase