由于虚拟机提前完毕 运行截图我就不上传了
直接上代码》》
因为我取出的数据为编码,需要使用UTF-8转换一下
package Flink_HBase_APL
import org.apache.hadoop.hbase.{HBaseConfiguration, TableName}
import org.apache.hadoop.hbase.client.{ConnectionFactory, Get}
import org.apache.hadoop.hbase.util.Bytes
/*
读取数据(hbase)
*/
object this_two {
def main(args: Array[String]): Unit = {
//建立hbase连接
val conf = HBaseConfiguration.create()
conf.set("hbase.zookeeper.quorum", "master,slave1,slave2")
conf.set("hbase.zookeeper.property.clientPort", "2181")
val connection = ConnectionFactory.createConnection(conf)
//获取table
val table = connection.getTable(TableName.valueOf("NB:t1"))
//配置行键
val rowkey = "2008"
val get = new Get(rowkey.getBytes)
//创建get
val result = table.get(get)
//参数:列族,列
val nameValue = result.getValue("info".getBytes,"name".getBytes)
//数据格式转换
val str = new String(nameValue,"UTF-8")
//val ageValue = result.getValue("info".getBytes,"age".getBytes)
//val schoolValue = result.getValue("info".getBytes,"school".getBytes)
//输出数据
println(str)
//关闭table
table.close()
//关闭hbase连接
connection.close()
}
}