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

在Java应用中,成功连接到运行在虚拟机上的HBase并获取表信息,但在尝试向HBase表中执行put操作时程序卡住,导致这个问题的原因可能是配置、网络延迟或HBase客户端与服务端版本不匹配。异常信息提示为`org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException`。
摘要由CSDN通过智能技术生成

通过查看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();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值