hbase代码报错(以及解决方法)

编程入门 行业动态 更新时间:2024-10-22 02:56:30

hbase代码<a href=https://www.elefans.com/category/jswz/34/1771188.html style=报错(以及解决方法)"/>

hbase代码报错(以及解决方法)

》》》直接上代码 

package HBase_Apiimport org.apache.hadoop.conf.Configuration
import org.apache.hadoop.hbase.{HBaseConfiguration, TableName}
import org.apache.hadoop.hbase.client.{Connection, ConnectionFactory, Get, Put}
import org.apache.hadoop.hbase.util.Bytesobject HBase_judgment {def main(args: Array[String]): Unit = {// HBase配置val conf = HBaseConfiguration.create()conf.set("hbase.zookeeper.quorum", "master,slave1,slave2") // 设置ZooKeeper的主机名或IP地址conf.set("hbase.zookeeper.property.clientPort", "2181") // 设置ZooKeeper客户端连接端口val connection = ConnectionFactory.createConnection(conf)println(connection)val damin = connection.getAdminval tableExists = damin.tableExists(TableName.valueOf("nike:n1"))//表名if (tableExists) {println("you")}else{println("wu")}val table = connection.getTable(TableName.valueOf("nike:n1"))val rowkey = "101" //行键val get = new Get(rowkey.getBytes)val result = table.get(get)val nameValue = result.getValue("mag".getBytes,"age".getBytes)val str = new String(nameValue)   //讲读取的数据转换成stringprintln(str)try {val table = connection.getTable(TableName.valueOf("nike:n1"))val put = new Put(Bytes.toBytes("103"))  //行键put.addColumn(Bytes.toBytes("mag"), //列族Bytes.toBytes("name"), //列名Bytes.toBytes("wanhaihang")  //数值)put.addColumn(Bytes.toBytes("mag"), //列族Bytes.toBytes("age"), //列名Bytes.toBytes("19")  //数值)//将数据写入表中table.put(put)//关闭tabletable.close()}//测试输出代码(可有可无         )println("成功插入数值")damin.close()table.close()connection.close()}}

》》》报错 

》》》 解决方法(映射有问题)

 》》》重新运行

》》》结果

更多推荐

hbase代码报错(以及解决方法)

本文发布于:2023-11-16 10:11:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1617584.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报错   解决方法   代码   hbase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!