hbase可以嵌入到java应用程序中吗?

时间:2013-01-18 17:13:53

标签: java hadoop hbase

我真的很擅长这个大数据,我需要知道可以将hbase嵌入到java应用程序中。

在java中开发的是否可以将hbase添加为库并执行操作?

如果是这样,任何人都可以提供简单的教程或示例代码。

2 个答案:

答案 0 :(得分:3)

您绝对可以编写Java应用程序来使用Hbase,主Hbase发行版中提供了一个Java API。

您应该从the official website获取最新版本,并获取可用于构建应用程序的hbase-0.xx.x.jar jar。如果你想查看hbase的类路径依赖关系,一旦安装了hbase,你就可以执行hbase classpath,这样就可以打印出你需要的jar列表。

你可能会发现很多Java应用程序在Google上进行Hbase操作的例子,但这里有一个常规操作的例子:

// get the hbase config
Configuration config = HBaseConfiguration.create();

// specify which table you want to use
HTable table = new HTable(config, "mytable");
// add a row to your table
Put p = new Put(Bytes.toBytes("myrow"));    
// specify the column family, column qualifier and column value
p.add(Bytes.toBytes("myfamily"), Bytes.toBytes("myqualifier"), Bytes.toBytes("myvalue"));
// commit to your table
table.put(p);

// define which row you want to get 
Get g = new Get(Bytes.toBytes("myrow"));
// get your row
Result r = table.get(g);
// choose what you want to extract from your row
byte[] value = r.getValue(Bytes.toBytes("myfamily"), Bytes.toBytes("myqualifier"));
// convert to a string
System.out.println("GET: " + Bytes.toString(value)); 

// do a scan operation
Scan s = new Scan();
s.addColumn(Bytes.toBytes("myfamily"), Bytes.toBytes("myqualifier"));
ResultScanner scanner = table.getScanner(s);

答案 1 :(得分:3)

HBase不运行嵌入式它运行在Hadoop之上,它针对的是大数据和大量服务器。

它有一个可以使用的Java API,例如Charles Menguy的回复