Kathick
Kathick

Reputation: 1405

Can hbase be embedded in java applications?

I am really new to this big data i need to know can hbase be embedded in java application.

As is it developed in java can hbase be added as an library and do the operations?

If so can any one give an simple tutorial or sample code.

Upvotes: 4

Views: 3248

Answers (2)

Arnon Rotem-Gal-Oz
Arnon Rotem-Gal-Oz

Reputation: 25909

HBase does not run embedded it runs on top of Hadoop and it is aimed at big data and a large number of servers.

It does have a Java API which you can use e.g. Charles Menguy's reply

Upvotes: 4

Charles Menguy
Charles Menguy

Reputation: 41428

You can definitely write a Java application to use Hbase, there is a Java API that is provided in the main Hbase distribution.

You should take the latest build from the official website and get the hbase-0.xx.x.jar jar that you can use to build your application. If you want to look at classpath dependencies for hbase, once you installed hbase you can just do hbase classpath and that should print you the list of jars you need.

You can probably find a lot of example of Java apps doing Hbase operations on Google, but here is an example for the usual operations:

// 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);

Upvotes: 3

Related Questions