Part5---Java连接HBase读取数据
01.加载maven依赖<dependency><groupId>org.apache.hbase</groupId><artifactId>hbase-client</artifactId><version>2.1.1</version></dependency>02.准备数据在dbeaver上显示
·
01.加载maven依赖
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>2.1.1</version>
</dependency>
02.准备数据
在dbeaver上显示为:
03.连接读取数据
hbase.zookeeper.quorum使用的是Zookeeper的信息
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
public class JavaConectHbase {
public static void main(String[] args) throws Exception{
Configuration conf = new Configuration();
conf.set("hbase.zookeeper.quorum", "192.168.1.10:2181");
try {
Connection connection = ConnectionFactory.createConnection(conf);
// Admin admin = connection.getAdmin();
System.out.println("连接测试通过");
} catch (Exception e){
e.printStackTrace();
}
Connection conn = ConnectionFactory.createConnection(conf);
Table gadaite = conn.getTable(TableName.valueOf("Gadaite"));
ResultScanner scanner = gadaite.getScanner(new Scan());
for (Result sc:scanner){
for (Cell c:sc.rawCells()){
System.out.println(c);
}
}
}
}
输出结果:
更多推荐
已为社区贡献1条内容
所有评论(0)