hbase连接操作

package com.test;
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.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;

public class Test {


    
    public static void main(String[] args) {
        
        // 连接
        Connection conn = null;
        HTable messages = null;
        String TABLE_NAME = "mytest";
        
        Configuration configuration = HBaseConfiguration.create();
        configuration.set("hbase.zookeeper.property.clientPort", "2181");
        configuration.set("hbase.zookeeper.quorum","192.168.1.21:2181,192.168.1.22:2181,192.168.1.23:2181");
        configuration.set("hbase.master", "192.168.1.21:60000");
        

        
        try {
            conn = ConnectionFactory.createConnection(configuration);
            messages = (HTable) conn.getTable(TableName.valueOf(TABLE_NAME));
            System.out.println("连接到表"+messages);
            
                        Get g = new Get("287998723".getBytes());
                        Result r = messages.get(g);
                        /*byte [] value = r.getValue(Bytes.toBytes("msg"),
                           Bytes.toBytes("content"));
            String valueStr = Bytes.toString(value);*/
            
            System.out.println("Get r1 content: " );
            
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }

}

 

posted on 2016-11-08 14:52  充实自己  阅读(7471)  评论(0编辑  收藏  举报