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的更多相关文章
随机推荐
- 少年的u
发现了我提取DNa的过程存在问题,能够跑出action 但是不能克隆出基因.老师给我解释了为什么,说是我的DNA质量不是很高.但是在接下来的时间我会解决这个问题. 和师姐一起去上面的实验室,看了定量P ...
- Jmeter录制https协议不能跳转成功(证书导入)
原文: http://www.cnblogs.com/Lam7/p/7154120.html 录制脚本的时候,比如录制https协议的百度网站 https://www.baidu.com ,所有录制 ...
- samba搭建共享目录
centos 中使用docker 运行samba docker pull dperson/samba 运行一下命令 docker run -it -p 139:139 -p 445:445 --nam ...
- PolandBall and Forest
PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirect ...
- youtube-dl parameters
how to select the format of vidoes from youtube-dl? https://www.jianshu.com/p/611009843919 https://u ...
- amazon 1
# 跨境电商 Amazon 丰富强大的海外站 开店流程 https://www.cifnews.com/article/48921 注册事项以及二审怎么过 https://www.cifnews.co ...
- abb画学号
MODULE Module2 VAR signaldi signaldi26; VAR signaldi signaldi37; VAR signaldi signaldi48; PROC main2 ...
- codeforces 1269D. Domino for Young (二分图证明/结论题)
链接:https://codeforces.com/contest/1269/problem/D 题意:给一个不规则的网格,在上面放置多米诺骨牌,多米诺骨牌长度要么是1x2,要么是2x1大小,问最多放 ...
- 2019-08-05 纪中NOIP模拟B组
T1 [JZOJ1432] 输油管道 题目描述 请你帮忙设计一个从城市M到城市Z的输油管道,现在已经把整个区域划分为R行C列,每个单元格可能是空的也可能是以下7种基本管道之一: 油从城市M流向Z,‘+ ...
- OpenCV图像载入、显示和输出到文件以及滑块的使用
图像载入 imread()函数 Mat imread(const string& filename, int flags = 1); 第一个参数为文件名 第二个参数为载入标识 flags &g ...