解决问题步骤包括
1、查看输入参数是否正确
2、查看连接是否建立
3、查看值是否有传到
先上代码
public String getValue(String tableName,String rowKey,String family,String column){
String res = ""; //返回结果
Table table = null;
if (StringUtils.isBlank(tableName) || StringUtils.isBlank(family) //判断输入值是否为空
|| StringUtils.isBlank(rowKey) || StringUtils.isBlank(column)) {
return null;
}
try{
connection = ConnectionFactory.createConnection( con.configuration() ); // hbase链接
table = connection.getTable( TableName.valueOf( tableName ) );
Get g = new Get( rowKey.getBytes() );
g.addColumn( family.getBytes(),column.getBytes() );
Result result = table.get( g );
List<Cell> ceList = result.listCells();
if (ceList != null && ceList.size() > 0) {
for (Cell cell : ceList) {
res = Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
}
}
}catch (Exception e){
e.printStackTrace();
}
return res;
}
yml文件
hbase:
config:
hbase.zookeeper.quorum: 172.18.2.161,172.18.2.162,172.18.2.163
hbase.zookeeper.property.clientPort: 2181
zookeeper.znode.parent: /hbase-unsecure
1、参数连接没问题,注意行键的意义,如果参数有问题的话,会报另一个错
2、连接建立过程,zookeeper使用的是172.168.246.160、161、162三个节点,一开始我用telnet去连这个端口连成功了,还以为是能达到这个端口,但事实 证明,telnet能到,zookeeper不一定能到。询问之后才知道,在虚拟机上,当初建的虚拟机器的名字是 node201\node202\node203,遂在host加入相关的 配置,然后就跑通了。
3、提示
Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
这个是因为你本地没有装withutils.exe这个管理工具,因此才会有错,但本地连hbase(不管理)是可以不用装的,所以这个错误暂时没有去动它。