Java_Habse_add
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table; public class HBaseTest2 {
public static Configuration configuration;
public static Connection connection;
public static Admin admin; public static void main(String[] args) {
configuration=HBaseConfiguration.create();
configuration.set("hbase.rootdir", "hdfs://localhost:9000/hbase"); /*
try {
connection=ConnectionFactory.createConnection(configuration);
admin=connection.getAdmin();
insertRow("Student","scofield","score","English","45");
insertRow("Student","scofield","score","Math","89");
insertRow("Student","scofield","score","Computer","100");
System.out.println("插入成功!---李运辰");
} catch (IOException e) {
e.printStackTrace();
}
*/
configuration.set("hbase.rootdir", "hdfs://localhost:9000/hbase");
try {
connection=ConnectionFactory.createConnection(configuration);
admin=connection.getAdmin();
getData("Student","scofield","score","English");
System.out.println("输出完成!---李运辰");
} catch (IOException e) {
e.printStackTrace();
} close();
} public static void insertRow(String tableName, String rowKey, String colFamily, String col, String val) {
try {
Table table = connection.getTable(TableName.valueOf(tableName));
Put put = new Put(rowKey.getBytes());
put.addColumn(colFamily.getBytes(), col.getBytes(), val.getBytes());
table.put(put);
table.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } public static void getData(String tableName, String rowKey, String colFamily, String col) {
try {
Table table = connection.getTable(TableName.valueOf(tableName));
Get get=new Get(rowKey.getBytes());
get.addColumn(colFamily.getBytes(), col.getBytes());
Result result=table.get(get);
showCell(result);
table.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } private static void showCell(Result result) {
Cell[] cells=result.rawCells();
for(Cell cell:cells) {
System.out.println("RowName:"+new String(CellUtil.cloneRow(cell))+" ");
System.out.println("Timetamp:"+cell.getTimestamp()+" ");
System.out.println("column Family"+new String(CellUtil.cloneFamily(cell))+" ");
System.out.println("row Name:"+new String(CellUtil.cloneValue(cell))+" ");
System.out.println("value"+new String(CellUtil.cloneValue(cell))+" "); } }
public static void close() { try {
if (admin != null) {
admin.close();
}
if(null!=connection) {
connection.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } }
Java_Habse_add的更多相关文章
随机推荐
- linux学习笔记1:linux驱动设备概述
- Linux - Shell - 算数表达式 - 位运算
概述 shell 中基于 $(()) 的 位运算 背景 复习 shell 脚本 凑数吧 准备 环境 os centos7 1. 位运算 代码 #!/bin/bash # 位运算 arg1=2 arg2 ...
- PP: UMAP: uniform manifold approximation and projection for dimension reduction
From Tutte institute for mathematics and computing Problem: dimension reduction Theoretical foundati ...
- valign
值 描述 top 对内容进行上对齐. middle 对内容进行居中对齐(默认值). bottom 对内容进行下对齐. baseline 与基线对齐.
- python3练习100题——018
原题链接:http://www.runoob.com/python/python-exercise-example18.html 题目:求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个 ...
- MonoBehaviour单例的另外一种省事的写法
using UnityEngine; public class CommSystem: SingletonGeneric<CommSystem> { public static strin ...
- mysql 原有的主键情况下设置自增字段
mysql 的自增字段只能是主键,如果原表已经有主键,需要设置自增字段应该怎么做呢? 1.alter table bu_staff drop primary key; 先删除表的主键 id为原表 ...
- python之路之socket
一.网络编程 1.socket介绍 import socket def handle_request(client): buf = client.recv(1024) client.sendall(b ...
- 什么是文件的BOM头,及BOM头有哪些坑?
1.什么是BOM? BOM是用来判断文本文件是哪一种Unicode编码的标记,其本身是一个Unicode字符("\uFEFF"),位于文本文件头部. 在不同的Unicode编码中, ...
- 第三十二篇 玩转数据结构——AVL树(AVL Tree)
1.. 平衡二叉树 平衡二叉树要求,对于任意一个节点,左子树和右子树的高度差不能超过1. 平衡二叉树的高度和节点数量之间的关系也是O(logn) 为二叉树标注节点高度并计算平衡因子 AVL ...