Java_Habse_add

1 1 import java.io.IOException; 2 2 import org.apache.hadoop.conf.Configuration; 3 3 import org.apache.hadoop.hbase.HBaseConfiguration; 4 4 import org.apache.hadoop.hbase.TableName; 5 5 import org.apache.hadoop.hbase.client.Admin; 6 6 import org.apache.hadoop.hbase.client.Connection; 7 7 import org.apache.hadoop.hbase.client.ConnectionFactory; 8 8 import org.apache.hadoop.hbase.client.Put; 9 9 import org.apache.hadoop.hbase.Cell; 10 10 import org.apache.hadoop.hbase.CellUtil; 11 11 import org.apache.hadoop.hbase.client.Get; 12 12 import org.apache.hadoop.hbase.client.Result; 13 13 import org.apache.hadoop.hbase.client.Table; 14 14 15 15 16 16 public class HBaseTest2 { 17 17 public static Configuration configuration; 18 18 public static Connection connection; 19 19 public static Admin admin; 20 20 21 21 public static void main(String[] args) { 22 22 configuration=HBaseConfiguration.create(); 23 23 configuration.set("hbase.rootdir", "hdfs://localhost:9000/hbase"); 24 24 25 25 /* 26 26 try { 27 27 connection=ConnectionFactory.createConnection(configuration); 28 28 admin=connection.getAdmin(); 29 29 insertRow("Student","scofield","score","English","45"); 30 30 insertRow("Student","scofield","score","Math","89"); 31 31 insertRow("Student","scofield","score","Computer","100"); 32 32 System.out.println("插入成功!---李运辰"); 33 33 } catch (IOException e) { 34 34 e.printStackTrace(); 35 35 } 36 36 */ 37 37 configuration.set("hbase.rootdir", "hdfs://localhost:9000/hbase"); 38 38 try { 39 39 connection=ConnectionFactory.createConnection(configuration); 40 40 admin=connection.getAdmin(); 41 41 getData("Student","scofield","score","English"); 42 42 System.out.println("输出完成!---李运辰"); 43 43 } catch (IOException e) { 44 44 e.printStackTrace(); 45 45 } 46 46 47 47 48 48 49 49 50 50 close(); 51 51 } 52 52 53 53 public static void insertRow(String tableName, String rowKey, String colFamily, String col, String val) { 54 54 try { 55 55 Table table = connection.getTable(TableName.valueOf(tableName)); 56 56 Put put = new Put(rowKey.getBytes()); 57 57 put.addColumn(colFamily.getBytes(), col.getBytes(), val.getBytes()); 58 58 table.put(put); 59 59 table.close(); 60 60 } catch (IOException e) { 61 61 // TODO Auto-generated catch block 62 62 e.printStackTrace(); 63 63 } 64 64 65 65 } 66 66 67 67 68 68 public static void getData(String tableName, String rowKey, String colFamily, String col) { 69 69 try { 70 70 Table table = connection.getTable(TableName.valueOf(tableName)); 71 71 Get get=new Get(rowKey.getBytes()); 72 72 get.addColumn(colFamily.getBytes(), col.getBytes()); 73 73 Result result=table.get(get); 74 74 showCell(result); 75 75 table.close(); 76 76 } catch (IOException e) { 77 77 // TODO Auto-generated catch block 78 78 e.printStackTrace(); 79 79 } 80 80 81 81 } 82 82 83 83 private static void showCell(Result result) { 84 84 Cell[] cells=result.rawCells(); 85 85 for(Cell cell:cells) { 86 86 System.out.println("RowName:"+new String(CellUtil.cloneRow(cell))+" "); 87 87 System.out.println("Timetamp:"+cell.getTimestamp()+" "); 88 88 System.out.println("column Family"+new String(CellUtil.cloneFamily(cell))+" "); 89 89 System.out.println("row Name:"+new String(CellUtil.cloneValue(cell))+" "); 90 90 System.out.println("value"+new String(CellUtil.cloneValue(cell))+" "); 91 91 92 92 } 93 93 94 94 } 95 95 public static void close() { 96 96 97 97 try { 98 98 if (admin != null) { 99 99 admin.close(); 100100 } 101101 if(null!=connection) { 102102 connection.close(); 103103 } 104104 } catch (IOException e) { 105105 // TODO Auto-generated catch block 106106 e.printStackTrace(); 107107 } 108108 109109 } 110110 111111 }
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )