IT咨询服务Hadoopeclipsehbase

Eclipse中无法执行hadoop HBase程序

Eclipse中执行hadoop程序报错,本地安装的Eclipse已经成功连接虚拟机上的Hadoop环境,在图片上的“左上角”有连接成功标志。请教各位高手,非常感谢!显示全部
Eclipse中执行hadoop程序报错,本地安装的Eclipse已经成功连接虚拟机上的Hadoop环境,在图片上的“左上角”有连接成功标志。


请教各位高手,非常感谢!收起
参与8

查看其它 6 个回答hn5092的回答

hn5092hn5092软件开发工程师递优
package com.x.hbase;

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.MasterNotRunningException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.Delete;
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.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Before;
import org.junit.Test;
public class HBaseDemo {
        Configuration conf;
        @Before
        public void init(){
                conf=HBaseConfiguration.create();
                conf.set("hbase.zookeeper.quorum","xym04:2181,xym05:2181,xym06:2181");
        }
       
       
        @Test //insert row
        public void testPut() throws IOException{
                HTable table =new HTable(conf, "people");
                Put put =new Put(Bytes.toBytes("kr0001"));
                put.add(Bytes.toBytes("info"), Bytes.toBytes("name"), Bytes.toBytes("zhangsanfeng"));
                put.add(Bytes.toBytes("info"), Bytes.toBytes("age"), Bytes.toBytes("111"));
                put.add(Bytes.toBytes("info"), Bytes.toBytes("money"), Bytes.toBytes(300000));
                table.put(put);
                table.close();
               
        }
       
       
        @Test //select row
        public void testGet() throws IOException{
                HTable table=new HTable(conf, "people");
                Get get=new Get(Bytes.toBytes("kr0001"));
                Result result = table.get(get);
                byte[] value = result.getValue(Bytes.toBytes("info"), Bytes.toBytes("age"));
                System.out.println(Bytes.toString(value));
                table.close();
               
        }
        @Test
        public void testScan() throws IOException{
                HTable table =new HTable(conf,"people");
                Scan san=new Scan();//begin end 左闭右开
                ResultScanner scanner = table.getScanner(san);
                for(Result r:scanner){
                        byte[] value = r.getValue(Bytes.toBytes("info"), Bytes.toBytes("age"));
                        System.out.println(Bytes.toString(value));
                }
                table.close();
        }
        @Test
        public void testDelete() throws IOException{
                HTable table = new HTable(conf, "people");
                Delete delete = new Delete(Bytes.toBytes("kr0001"));
                table.delete(delete);
                table.close();
        }
       
        //create table
        public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
                Configuration         conf=HBaseConfiguration.create();
                conf.set("hbase.zookeeper.quorum","xym04:2181,xym05:2181,xym06:2181");
                HBaseAdmin admin=new HBaseAdmin(conf);
                HTableDescriptor htd=new HTableDescriptor(TableName.valueOf("people"));
                HColumnDescriptor hcDescriptor=new HColumnDescriptor("info");
                HColumnDescriptor hcDescriptor2=new HColumnDescriptor("data");
                hcDescriptor.setMaxVersions(3);
                htd.addFamily(hcDescriptor);
                htd.addFamily(hcDescriptor2);
                admin.createTable(htd);
                admin.close();
        }
}

使用插件连接上去跟你使用hbase是没有任何关系的,你还是需要自己手动去连接hbase然后才可以使用它,这里是我的一个demo 你可以参照一下
软件开发 · 2015-09-21
浏览1861

回答者

hn5092
软件开发工程师递优

hn5092 最近回答过的问题

回答状态

  • 发布时间:2015-09-21
  • 关注会员:1 人
  • 回答浏览:1861
  • X社区推广