HBase 客户端通过Java访问集群

Hive有客户端,HBase也有客户端咯

hBase如何通过客户端连接呢?  简单的程序帮助你连接你的Hbase,很简单,很实用。

public class App {
	private static  HBaseAdmin admin = null;
	public static Configuration configuration; 
	public App() throws MasterNotRunningException, ZooKeeperConnectionException, IOException{
		configuration = HBaseConfiguration.create(); 
        configuration.set("hbase.zookeeper.property.clientPort", "2181"); 
        configuration.set("hbase.zookeeper.quorum", "192.168.222.128"); 
        configuration.set("hbase.master", "192.168.222.128:60000"); 
        System.out.println(configuration);
        admin = new HBaseAdmin(configuration);  
    } 

	public static void main(String[] args) throws Exception{
		App app = new App();
		app.getAllTables();
		
	}
    public List getAllTables() {  
        List<String> tables = null;  
        if (admin != null) {  
            try {  
            	System.out.println("here");
            	System.out.println(admin.isMasterRunning());
                HTableDescriptor[] allTable = admin.listTables();  
                System.out.println(allTable.length);
                if (allTable.length > 0)  
                    tables = new ArrayList<String>();  
                for (HTableDescriptor hTableDescriptor : allTable) {  
                    tables.add(hTableDescriptor.getNameAsString());  
                    System.out.println(hTableDescriptor.getNameAsString());  
                }  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
        return tables;  
    }  
}
上面的一些配置信息都是在hbase-site.xml中存在的。

具体的,可以查看你们的配置文件。

那么连接就会成功了吗???????

执行到这里就不动了。。。。。。。。

换另一个程序,报的错误是 hostException: ubuntu

so。。。。。。

win+R: drivers /etc/hosts  添加你的host配置:   192.168.222.128  ubuntu

再次访问,就ok了

部分结果显式:

3(共3张表)
member
student
test

连接完成。


不讲大道理,不讲深操作,只教你入门。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值