报错(以及解决方法)"/>
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代码报错(以及解决方法)
发布评论