hbase的API
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import java.io.IOException;
import java.util.ArrayList; public class HbaseClients {
public static Connection connection;
public static void main(String[] args) throws Exception {
create("kgc","cf1","cf2","cf3");
//delete("kgc");
//scan("test02");
}
//初始化的参数,连接对象
static {
//conf
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "192.168.159.110");
conf.set("hbase.zookeeper.property.clientPort","");
//获取hbase链接对象ConnectionFactory
try {
connection = ConnectionFactory.createConnection(conf);
} catch (IOException e) {
e.printStackTrace();
}
}
//创建表
public static void create(String table,String ... familys) throws Exception {
//首先要拿到admin
Admin admin = connection.getAdmin();
//new
HTableDescriptor htable = new HTableDescriptor(TableName.valueOf(table));
//htable
for (String family : familys) {
htable.addFamily(new HColumnDescriptor(family));
}
admin.createTable(htable);
System.out.println("创建成功");
}
//删除表
public static void delete(String table) throws Exception {
Admin admin = connection.getAdmin();
//判断表是否存在
if(admin.tableExists(TableName.valueOf(table))){
//下线了
admin.disableTable(TableName.valueOf(table));
//删除
admin.deleteTable(TableName.valueOf(table));
System.out.println("删除成功");
}else{
System.out.println("对不起,表不存在");
}
}
//添加数据
public static void adddata(String table,String rowkey,String columnFamily,String column,String value) throws Exception {
Table table1 = connection.getTable(TableName.valueOf(table));
//NEW PUT
Put puts = new Put(Bytes.toBytes(rowkey));
//puts
puts.add(Bytes.toBytes(columnFamily),Bytes.toBytes(column),Bytes.toBytes(value));
table1.put(puts);
System.out.println("添加数据成功");
}
//删除一行(rowkey)数据
public static void delterow(String table,String rowkey) throws Exception {
Table table1 = connection.getTable(TableName.valueOf(table));
//new Delete
Delete deletes = new Delete(Bytes.toBytes(rowkey));
//删除
table1.delete(deletes);
System.out.println("删除一行数据成功");
}
//删除多行数据
public static void deleterows(String table,String ... rowkeys) throws Exception {
Table table1 = connection.getTable(TableName.valueOf(table));
//new List
ArrayList<Delete> list = new ArrayList<>();
for (String rowkey : rowkeys) {
list.add(new Delete(Bytes.toBytes(rowkey)));
}
table1.delete(list);
System.out.println("删除多行成功");
}
//scan扫描
public static void scan(String table) throws Exception {
Table table1 = connection.getTable(TableName.valueOf(table));
//new Scan
Scan scan = new Scan();
//results 就是所有的rowkey的集合
ResultScanner results = table1.getScanner(scan);
for (Result result : results) {
//cells 的集合
Cell[] cells = result.rawCells();
for (Cell cell : cells) {
System.out.println(Bytes.toString(cell.getRow()));
System.out.println(Bytes.toString(cell.getFamily()));
System.out.println(Bytes.toString(cell.getQualifier()));
System.out.println(Bytes.toString(cell.getValue()));
}
}
}
//get
public static void get(String table,String rowkey) throws Exception {
Table table1 = connection.getTable(TableName.valueOf(table));
//new Get
Get get = new Get(Bytes.toBytes(rowkey));
Result result = table1.get(get);
Cell[] cells = result.rawCells();
for (Cell cell : cells) {
System.out.println(Bytes.toString(cell.getRow()));
System.out.println(Bytes.toString(cell.getFamily()));
System.out.println(Bytes.toString(cell.getQualifier()));
System.out.println(Bytes.toString(cell.getValue()));
}
}
}
hbase的API的更多相关文章
- Hbase客户端API基础小结笔记(未完)
客户端API:基础 HBase的主要客户端接口是由org.apache.hadoop.hbase.client包中的HTable类提供的,通过这个类,用户可以完成向HBase存储和检索数据,以及删除无 ...
- HBase伪分布式环境下,HBase的API操作,遇到的问题
在hadoop2.5.2伪分布式上,安装了hbase1.0.1.1的伪分布式 利用HBase的API创建个testapi的表时,提示 Exception in thread "main&q ...
- 使用hbase的api创建表时出现的异常
/usr/lib/jvm/java-7-openjdk-amd64/bin/java -Didea.launcher.port=7538 -Didea.launcher.bin.path=/usr/l ...
- hbase rest api接口链接管理【golang语言版】
# go-hbase-resthbase rest api接口链接管理[golang语言版]关于hbase的rest接口的详细信息可以到官网查看[http://hbase.apache.org/boo ...
- HBase Python API
HBase Python API HBase通过thrift机制可以实现多语言编程,信息通过端口传递,因此Python是个不错的选择 吐槽 博主在Mac上配置HBase,奈何Zoomkeeper一直报 ...
- Hadoop生态圈-Hbase的API常见操作
Hadoop生态圈-Hbase的API常见操作 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.
- HBase编程 API入门系列之create(管理端而言)(8)
大家,若是看过我前期的这篇博客的话,则 HBase编程 API入门系列之put(客户端而言)(1) 就知道,在这篇博文里,我是在HBase Shell里创建HBase表的. 这里,我带领大家,学习更高 ...
- hbase java api样例(版本1.3.1,新API)
hbase版本:1.3.1 目的:HBase新API的使用方法. 尝试并验证了如下几种java api的使用方法. 1.创建表 2.创建表(预分区) 3.单条插入 4.批量插入 5.批量插入(客户端缓 ...
- HBase编程 API入门系列之delete(客户端而言)(3)
心得,写在前面的话,也许,中间会要多次执行,连接超时,多试试就好了. 前面的基础,如下 HBase编程 API入门系列之put(客户端而言)(1) HBase编程 API入门系列之get(客户端而言) ...
- HBase编程 API入门系列之get(客户端而言)(2)
心得,写在前面的话,也许,中间会要多次执行,连接超时,多试试就好了. 前面是基础,如下 HBase编程 API入门系列之put(客户端而言)(1) package zhouls.bigdata.Hba ...
随机推荐
- Result window is too large, from + size must be less than or equal to: [10000] but was [78440]. See the scroll api for a more efficient way to request large data sets
{"error":{"root_cause":[{"type":"query_phase_execution_exception& ...
- 05-转置-置换-向量空间R
一.置换矩阵 一个矩阵的行或者列交换,可以借助另外一个矩阵相乘来实现 首先是行交换: $\underbrace{\left[\begin{array}{ccc}{1} & {1} & ...
- [转载]Quartus ii 一些Warning/Eeror分析与解决
我会在此基础上继续添加 原文地址:ii 一些Warning/Eeror分析与解决">Quartus ii 一些Warning/Eeror分析与解决作者:yanppf 注:http:// ...
- 使nginx归于systemd管理
[root@centos7 ~]# vim /usr/lib/systemd/system/nginx.service [Unit] Description=The Nginx HTTP Server ...
- 在C语言中连续使用scanf()函数出现的问题
#include<stdio.h> int main() { ],*c; printf("input string:\n"); scanf("%c" ...
- 一个有python扩展库的下载网站
https://www.lfd.uci.edu/~gohlke/pythonlibs/
- 03javascript01
1.javascript语法体系 1)EMCA基础语法(统一) 2)BOM编程(不统一) 3)DOM编程(不统一) 1.1 javascript使用 <!DOCTYPE html> < ...
- 十、S3C2440 开发资源
10.1 S3C2440 内部资源 1.2V 内核供电, 1.8V/2.5V/3.3V 储存器供电, 3.3V 外部 I/O 供电,具备 16KB 的指令缓存和 16KB 的数据缓存和 MMU 的微处 ...
- dd命令注意:dd:unrecognized operand 'if'
如果是 idd if=boot.bin 在等号两边不要有空格
- STM32 JTAG接口SWD下载接线图