数据写入HBase(scala)

Scala 复制代码
package source

import org.apache.hadoop.hbase.{HBaseConfiguration, TableName}
import org.apache.hadoop.hbase.client.{ConnectionFactory, Put}
import org.apache.hadoop.hbase.util.Bytes

object 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)
      //关闭table
      table.close()
    }
    //测试输出代码(可有可无)
    println("成功插入数值")
    //关闭hbase连接
    connection.close()

  }
}

在HBase里面查看:

相关推荐
梁萌1 小时前
ShardingSphere分库分表实战
数据库·mysql·实战·shardingsphere·分库分表
川石课堂软件测试1 小时前
Mysql中触发器使用详详详详详解~
数据库·redis·功能测试·mysql·oracle·单元测试·自动化
鹏说大数据1 小时前
数据治理项目实战系列6-数据治理架构设计实战,流程 + 工具双架构拆解
大数据·数据库·架构
唯余旧忆2 小时前
【数据写入】达梦数据库(dm8)merge into写入时序数据速度慢的问题处理
数据库
小二·2 小时前
MyBatis基础入门《十四》多租户架构实战:基于 MyBatis 实现 SaaS 系统的动态数据隔离
数据库·架构·mybatis
白衣衬衫 两袖清风2 小时前
SQL联查案例
数据库·sql
ShirleyWang0122 小时前
VMware如何导入vmdk文件
linux·数据库
gugugu.3 小时前
Redis Set类型完全指南:无序集合的原理与应用
数据库·windows·redis
wang6021252183 小时前
为什么不采用级联删除而选择软删除
数据库·oracle
AI逐月3 小时前
Git 彻底清除历史记录
大数据·git·elasticsearch