能连接hbase打印出表名,但put时卡住

来源:12-14 -功能一之数据库访问DAO层方法定义

qq_多少幅度_0

2019-04-08

通过查看zookeeper,有hbase表的数据,在本地可以连上虚拟机中的hbase,能够获取表信息,但是在往hbase表中执行put时,卡住。hadoop版本2.7.6,hbase版本1.4.9。最终出现org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException

package com.tang.spark.utils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;

import java.io.IOException;

public class HbaseUtils {

private Connection conn = null;
private Configuration configuration = null;
private static HbaseUtils hbaseUtils = null;
private HbaseUtils() throws IOException {
    configuration = HBaseConfiguration.create();
    configuration.set("hbase.zookeeper.quorum","master:2181");
    configuration.set("habse.rootdir","hdfs://master:9000/hbase");
    conn = ConnectionFactory.createConnection(configuration);

// admin = new HBaseAdmin(configuration);
}

/**
 * 获取HbaseUtils实例
 * @return
 */
public static synchronized HbaseUtils getInstance() throws IOException {
    if (null == hbaseUtils){
        return new HbaseUtils();
    }
    return hbaseUtils;
}

/**
 *
 * @param tableName
 * @return
 */
public Table getTable(String tableName){
    Table hTable = null;
    try {
        hTable = conn.getTable(TableName.valueOf(tableName));
    }catch (Exception e){
        e.printStackTrace();
    }
    return hTable;
}

/**
 * 网hbase表中插入数据
 * @param tableName
 * @param rowKey
 * @param cf
 * @param colum
 * @param value
 */
public void put(String tableName,String rowKey,String cf,String colum,String value) throws IOException {

    Table table = getTable(tableName);
    Put put = new Put(rowKey.getBytes());
    put.addColumn(cf.getBytes(),colum.getBytes(),value.getBytes());
    table.put(put);
}

public void get(){

}

public static void main(String[] args) throws IOException {
    String tableName = "imooc_course_clickcount";
    String rowKey = "20190408_134";
    String cf = "info";
    String colum = "click_count";
    String value = "34";
    HbaseUtils instance = HbaseUtils.getInstance();
    System.out.println(instance.getTable(tableName).getName().getNameAsString());
    instance.put(tableName,rowKey,cf,colum,value);
    System.out.println();
    instance.conn.close();
}

}

写回答

2回答

qq_多少幅度_0

提问者

2019-04-08

在hbase的shell窗口可以执行put操作

0
0

Michael_PK

2019-04-08

你HBase shell操作put正常不

0
8
Michael_PK
回复
qq_多少幅度_0
下次就要更注意点了
2019-04-09
共8条回复

Spark Streaming实时流处理项目实战

Flume+Kafka+Spark Streaming 构建通用实时流处理平台

1404 学习 · 571 问题

查看课程