object SparkTest {
def main(args: Array[String]): Unit = { val sparkConf = new SparkConf().setAppName("SparkTest").setMaster("local") val sc = new SparkContext(sparkConf) val conf = HBaseConfiguration.create() conf.set("hbase.zookeeper.quorum", "ip地址") // 设置ZK集群地址也可以通过将HBASE-SITE.XML导入CLASSPATH(但是建议在程序里这样设置) conf.set("hbase.zookeeper.property.clientPort", "2181") // 设置ZK连接端口默认2181 conf.set("zookeeper.znode.parent", "/hbase-unsecure") import org.apache.hadoop.hbase.client.ConnectionFactory val conn = ConnectionFactory.createConnection(conf) val table = conn.getTable(TableName.valueOf("表名")) val get = new Get(Bytes.toBytes("rowkey")) val result = table.get(get) if (result.raw().length > 0) { println(new String(result.raw()(0).getValue, "utf-8").substring(0, 8)) } else { println("空") }
}