package sourceimport org.apache.hadoop.hbase.{HBaseConfiguration, TableName}
import org.apache.hadoop.hbase.client.{ConnectionFactory, Put}
import org.apache.hadoop.hbase.util.Bytesobject ffff {def main(args: Array[String]): Unit = {//hbase连接配置val conf = HBaseConfiguration.create()conf.set("hbase.zookeeper.quorum", "bigdata1,bigdata2,bigdata3")conf.set("hbase.zookeeper.property.clientPort", "2181")//创建hbase连接val connection = ConnectionFactory.createConnection(conf)try{//获取hbase表val table = connection.getTable(TableName.valueOf("test")) //表名//创建put对象插入数据val put = new Put(Bytes.toBytes("2008")) //行键put.addColumn(Bytes.toBytes("info"), //列族Bytes.toBytes("name"), //列名Bytes.toBytes("beijing") //数值)put.addColumn(Bytes.toBytes("info"), //列族Bytes.toBytes("age"), //列名Bytes.toBytes("70") //数值)put.addColumn(Bytes.toBytes("info"), //列族Bytes.toBytes("school"), //列名Bytes.toBytes("国家") //数值)//将数据写入表中table.put(put)//关闭tabletable.close()}//测试输出代码(可有可无)println("成功插入数值")//关闭hbase连接connection.close()}
}
在HBase里面查看: