public class Demo {
private Configuration conf;
private Connection conn; @Before
public void prepare() throws Exception {
conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "m6,m7,m8");
conn = ConnectionFactory.createConnection(conf);
} /**
* 创建表
*/
@Test
public void createTable() throws Exception {
Admin admin = conn.getAdmin();
TableName tableName = TableName.valueOf("t_person");
HTableDescriptor hTableDescriptor = new HTableDescriptor(tableName);
// 添加列簇
HColumnDescriptor baseInfo = new HColumnDescriptor("base_info");
hTableDescriptor.addFamily(baseInfo);
admin.createTable(hTableDescriptor);
admin.close();
conn.close();
} /**
* 删除表
* @throws Exception
*/
@Test
public void dropTable() throws Exception {
Admin admin = conn.getAdmin();
admin.disableTable(TableName.valueOf("t_person"));
admin.deleteTable(TableName.valueOf("t_person"));
admin.close();
} /**
* 插入数据
* @throws Exception
*/
@Test
public void put() throws Exception {
TableName tableName = TableName.valueOf("t_person");
// HTablePool pool = new HTablePool(conf, 10);
// HTable table = (HTable) pool.getTable("t_person");
Table table = conn.getTable(tableName);
// rowkey 行健
Put put = new Put(Bytes.toBytes("p_0001"));
put.addColumn(Bytes.toBytes("base_info"), Bytes.toBytes("name"), Bytes.toBytes("zhangsan"));
put.addColumn(Bytes.toBytes("base_info"), Bytes.toBytes("age"), Bytes.toBytes(18));
table.put(put);
table.close();
} /**
* 获取数据
* @throws IOException
*/
@Test
public void get() throws IOException {
TableName tableName = TableName.valueOf("t_person");
Table table = conn.getTable(tableName);
Get get = new Get(Bytes.toBytes("p_0001"));
Result result = table.get(get);
for (Cell cell : result.listCells()) { System.out.println(Bytes.toString(CellUtil.cloneFamily(cell)));
System.out.println(Bytes.toString(CellUtil.cloneQualifier(cell)));
System.out.println(Bytes.toInt(CellUtil.cloneValue(cell)));
}
} @Test
public void scan() throws IOException {
TableName tableName = TableName.valueOf("t_person");
Table table = conn.getTable(tableName);
Scan scan = new Scan();
// 根据Qualifier的开头字符进行过滤
ColumnPrefixFilter filter = new ColumnPrefixFilter(Bytes.toBytes("z"));
scan.setFilter(filter);
ResultScanner scanner = table.getScanner(scan);
for (Result result : scanner) {
for (Cell cell : result.listCells()) {
System.out.println(Bytes.toString(CellUtil.cloneFamily(cell)));
System.out.println(Bytes.toString(CellUtil.cloneQualifier(cell)));
}
}
}
}

  

hbase基本操作的更多相关文章

  1. 熟悉HBase基本操作

    1. ssh localhost start-dfs.sh start-hbase.sh hbase shell create 'Student', 'S_No', 'S_Name', 'S_Sex' ...

  2. Hbase记录-HBase基本操作(二)

    HBase Exists   可以使用exists命令验证表的存在.下面的示例演示了如何使用这个命令. hbase(main):024:0> exists 'emp' Table emp doe ...

  3. Hbase记录-HBase基本操作(一)

    HBase创建表 可以使用命令创建一个表,在这里必须指定表名和列族名.在HBase shell中创建表的语法如下所示. create ‘<table name>’,’<column ...

  4. HBase 基本操作

    如何添加列族 很简单,跟rdbms一样 直接用alter,但是alter之前必须先disable这个表 ---->disable 'test'                          ...

  5. hadoop之hbase基本操作

    hbase shell 进入hbase命令行 list 显示HBASE表 status 系统上运行的服务器的细节和系统的状态 version 返回HBase系统使用的版本 table_help 引导如 ...

  6. HBase基本操作-Java实现

    创建Table public static void createTable(String tableName){ try { HBaseAdmin hbaseAdmin = new HBaseAdm ...

  7. HBase笔记--编程实战

    HBase总结:http://blog.csdn.net/lifuxiangcaohui/article/details/39997205  (very good) Spark使用Java读取hbas ...

  8. 第四章:大数据 の HBase 基础

    本课主题 NoSQL 数据库介绍 HBase 基本操作 HBase 集群架构与设计介紹 HBase 与HDFS的关系 HBase 数据拆分和紧缩 引言 介绍什么是 NoSQL,NoSQL 和 RDBM ...

  9. Hadoop HA高可用集群搭建(Hadoop+Zookeeper+HBase)

    声明:作者原创,转载注明出处. 作者:帅气陈吃苹果 一.服务器环境 主机名 IP 用户名 密码 安装目录 master188 192.168.29.188 hadoop hadoop /home/ha ...

随机推荐

  1. The resource could not be loaded because the App Transport Security policy requires the use of a secure connection

    xmpp 项目中遇到的问题,用苹果的通信API 写一个PUT 方法,向服务器上传一张图片.遇到如题问题. Plist 文件没有NSAppTransportSecurity属性 Dic,添加该属性,再添 ...

  2. 【转】SQLServer内部原理

    原文地址:http://twb.iteye.com/blog/182083 在讲SQLSERVER内部原理的之前,我觉得非常有必要向大家介绍一下SQLSERVER的历史. 让我们站在1999年,看看计 ...

  3. 浏览器 user-agent 字符串的故事

    你是否好奇标识浏览器身份的User-Agent,为什么每个浏览器都有Mozilla字样? 故事还得从头说起,最初的主角叫NCSA Mosaic,简称Mosaic(马赛克),是1992年末位于伊利诺伊大 ...

  4. ip sevices

    http://www.ip138.com/ip2city.asp http://www.bliao.com/ip.phtml http://www.whereismyip.com/ http://ww ...

  5. 为什么数值类型byte取值范围是(-128~127)?

    在解决这个问题之前,我们先了解几个概念? 一.原码, 反码, 补码的概念 正数的反码和补码都与原码一样: 负数的反码.补码与原码不同,负数的反码:原码中除去符号位,其他的数值位取反,0变1,1变0.负 ...

  6. add user

    ubuntu adduser deploy usermod -a -G sudo deploy centos adduser deploy passwd deploy usermod -a -G wh ...

  7. 【转】Unity 之 移动设备的触控操作

    http://blog.csdn.net/anyuanlzh/article/details/18367941 这篇博文将简单的记录,如何用unity处理在移动设备上的触控操作.    iOS和And ...

  8. 在Vista或更高版本Windows系统中, 获取超大图标的办法

    这几天写个小东西, 需要获取系统正在运行的程序图标, 一般来说32*32就足够了, 不过既然Win7能够支持超大图标(256*256), 咱们也需要与时俱进, 说不定什么时候遇到个变态客户就有这要求了 ...

  9. MYSQL启动报1067错误,系统日志中是“服务 mysql 意外停止” Mysql日志中则是:“Plugin \'FEDERATED\' is disabled”

    MYSQL启动报1067错误,系统日志中是"服务 mysql 意外停止" Mysql日志中则是:"Plugin \'FEDERATED\' is disabled&quo ...

  10. 【转】Swing 与EDT线程

    在Swing程序中,经常能看到如下这种代码: SwingUtilities.invokeLater(new Runnable(){ @Override public void run() { text ...