Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 19th, 2013  |  syntax: Java  |  size: 1.15 KB  |  views: 52  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class SimpleWriteReadHbase {
  2.  
  3.         private final Configuration hConfig = HBaseConfiguration.create();
  4.  
  5.         public SimpleWriteReadHbase(){
  6.                 // hConfig.set("hbase.zookeeper.quorum", nameNode);
  7.                 hConfig.addResource("hbase-site.xml");
  8.         }
  9.  
  10.         public void putAValue() throws IOException{
  11.                 HTable table = new HTable(hConfig, "stops");
  12.  
  13.                 Put aPut = new Put("oneRow".getBytes("UTF-8"));
  14.                 aPut.add("data".getBytes("UTF-8"), "stuff".getBytes("UTF-8"), "nothing".getBytes("UTF-8"));
  15.                 table.put(aPut);
  16.                 table.close();
  17.         }
  18.  
  19.         public void getAValue() throws IOException{
  20.                 HTable table = new HTable(hConfig, "stops");
  21.  
  22.                 Get aGet = new Get("oneRow".getBytes("UTF-8"));
  23.                 Result result = table.get(aGet);
  24.                 byte[] resultBytes = result.getValue("stuff".getBytes("UTF-8"), "nothing".getBytes("UTF-8"));
  25.                 System.out.println(new String(resultBytes, "UTF-8"));
  26.                 table.close();
  27.         }
  28.  
  29.         /**
  30.          * @param args
  31.          */
  32.         public static void main(String[] args){
  33.                 SimpleWriteReadHbase sample = new SimpleWriteReadHbase();
  34.                 try{
  35.                         sample.putAValue();
  36.                         sample.getAValue();
  37.                 } catch(IOException e){
  38.                         // TODO Auto-generated catch block
  39.                         e.printStackTrace();
  40.                 }
  41.         }
  42. }
clone this paste RAW Paste Data