Fetch data from HTable
- Create Get instance with Row Key "rowkey1"
Get get = new Get(Bytes.toBytes("rowkey1"));
- Specify column family ("sig:botnet")
get.addColumn(Bytes.toBytes("sig"), Bytes.toBytes("botnet"));
Result result = htable.get(get);
- Get value of column family (sig:botnet ==> value)
byte[] val = result.getValue(Bytes.toBytes("sig"), Bytes.toBytes("botnet"));
System.out.println("Value:" + Bytes.toString(val));
Source Code
package org.hadoop.dna;
import java.io.IOException;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
public class SnortGet {
/**
* hbase table write example
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
try {
Configuration config = HBaseConfiguration.create();
config.addResource(new Path("/usr/local/hbase/conf/hbase-default.xml"));
config.addResource(new Path("/usr/local/hbase/conf/hbase-site.xml"));
// Load Hbase table
HTable htable = new HTable(config, "SnortTable");
// Get
// rowkey1 : sig:botnet -> sobic
Get get = new Get(Bytes.toBytes("rowkey1"));
get.addColumn(Bytes.toBytes("sig"), Bytes.toBytes("botnet"));
Result result = htable.get(get);
byte[] val = result.getValue(Bytes.toBytes("sig"), Bytes.toBytes("botnet"));
System.out.println("Value:" + Bytes.toString(val));
} catch (IOException e) {
System.out.println("IOExeption: cannot insert table");
e.printStackTrace();
}
}
}