Advertisement
Guest User

Untitled

a guest
Mar 19th, 2013
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement