Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SimpleWriteReadHbase {
- private final Configuration hConfig = HBaseConfiguration.create();
- public SimpleWriteReadHbase(){
- // hConfig.set("hbase.zookeeper.quorum", nameNode);
- hConfig.addResource("hbase-site.xml");
- }
- public void putAValue() throws IOException{
- HTable table = new HTable(hConfig, "stops");
- Put aPut = new Put("oneRow".getBytes("UTF-8"));
- aPut.add("data".getBytes("UTF-8"), "stuff".getBytes("UTF-8"), "nothing".getBytes("UTF-8"));
- table.put(aPut);
- table.close();
- }
- public void getAValue() throws IOException{
- HTable table = new HTable(hConfig, "stops");
- Get aGet = new Get("oneRow".getBytes("UTF-8"));
- Result result = table.get(aGet);
- byte[] resultBytes = result.getValue("stuff".getBytes("UTF-8"), "nothing".getBytes("UTF-8"));
- System.out.println(new String(resultBytes, "UTF-8"));
- table.close();
- }
- /**
- * @param args
- */
- public static void main(String[] args){
- SimpleWriteReadHbase sample = new SimpleWriteReadHbase();
- try{
- sample.putAValue();
- sample.getAValue();
- } catch(IOException e){
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement