HBase的JavaAPI使用
2014-05-31 13:03
375 查看
Java Client API Overview
HBase是用Java写的,支持用编程语言来动态操作管理数据库,能用命令行做的都能够用API来做。
主要的使用步骤例如以下:
1.创建一个 Configuration 对象
–从 HDFS 对象中调用 Configuration
–加入 HBase 属性
Configuration conf = HbaseConfiguration.create();
2.创建 HTable
–提供 Configuration 对象
–提供 表名
HTable hTable = new HTable(conf, tableName);
3.运行操作
–如 put, get, scan, delete, etc...
hTable.getTableName();
4.关闭 HTable 实例
–清空缓存
–释放资源
hTable.close();
以下是一个建表的样例:
以下是插入数据的样例:
HBase是用Java写的,支持用编程语言来动态操作管理数据库,能用命令行做的都能够用API来做。
主要的使用步骤例如以下:
1.创建一个 Configuration 对象
–从 HDFS 对象中调用 Configuration
–加入 HBase 属性
Configuration conf = HbaseConfiguration.create();
2.创建 HTable
–提供 Configuration 对象
–提供 表名
HTable hTable = new HTable(conf, tableName);
3.运行操作
–如 put, get, scan, delete, etc...
hTable.getTableName();
4.关闭 HTable 实例
–清空缓存
–释放资源
hTable.close();
以下是一个建表的样例:
import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.util.Bytes; public class ConstructHTable { public static void main(String[] args) throws IOException { Configuration conf = HBaseConfiguration.create(); HTable htable = new HTable(conf,"table-created_from_api"); System.out.println("Table :"+Bytes.toString(htable.getTableName())); htable.close(); } }
以下是插入数据的样例:
import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Put; import static org.apache.hadoop.hbase.util.Bytes.*; public class PutExample { public static void main(String[] args) throws IOException { Configuration conf = HBaseConfiguration.create(); HTable hTable = new HTable(conf, "HBaseSamples"); Put put1 = new Put(toBytes("row1")); put1.add(toBytes("test"), toBytes("col1"), toBytes("val1")); put1.add(toBytes("test"), toBytes("col2"), toBytes("val2")); hTable.put(put1); hTable.close(); } }
相关文章推荐
- HBase Java API使用(一)
- HBase总结(十一)hbase Java API 介绍及使用示例
- HBase总结(十一)hbase Java API 介绍及使用示例
- HBase-1.2.4使用新的Java API操作库常用方法使用
- Ubuntu下HBase安装与使用(shell+Java API)
- HBase Java API使用操作例子
- Hbase之Java API使用
- HBase 使用 Java Api 实现对数据的增删改查
- HBASE的javaAPI使用,建表,增,删,查,过滤器简单实用
- HBase java API 使用实例(二)——查询、分页
- HBase总结(十一)hbase Java API 介绍及使用示例
- 使用java HBase API查询 小bug记录
- HBase总结(十一)hbase Java API 介绍及使用示例
- Ubuntu下HBase安装与使用(shell+Java API)
- HBase客户端Java API使用总结
- HBase-1.0.1.1的Java API使用记录
- [hbase]使用HBase的Java api查询HBase
- 使用用Phoenix的Java api操作HBase
- HBase Java API介绍及使用示例
- Hbase-1.0+ Java API:BufferedMutatorExample,Hbase新API的使用