hbase中創(chuàng)建表、插入數(shù)據(jù),更新數(shù)據(jù),刪除數(shù)據(jù)的操作

本篇內(nèi)容介紹了“hbase中創(chuàng)建表、插入數(shù)據(jù),更新數(shù)據(jù),刪除數(shù)據(jù)的操作”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

從網(wǎng)站建設(shè)到定制行業(yè)解決方案,為提供網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)服務(wù)體系,各種行業(yè)企業(yè)客戶提供網(wǎng)站建設(shè)解決方案,助力業(yè)務(wù)快速發(fā)展。創(chuàng)新互聯(lián)將不斷加快創(chuàng)新步伐,提供優(yōu)質(zhì)的建站服務(wù)。

所需要的包有:
commons-codec-1.4.jar
commons-logging-1.1.1.jar
hadoop-0.20.2-core.jar
hbase-0.90.2.jar
log4j-1.2.16.jar
zookeeper-3.3.2.jar
 
背景:
假設(shè)有一個(gè)不知道是干什么表:)
表里需要存入人員和其相對(duì)應(yīng)的部門信息
 
代碼:

import java.util.ArrayList;import java.util.List;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.hadoop.hbase.HColumnDescriptor;import org.apache.hadoop.hbase.HTableDescriptor;import org.apache.hadoop.hbase.client.Delete;import org.apache.hadoop.hbase.client.HBaseAdmin;import org.apache.hadoop.hbase.client.HTable;import org.apache.hadoop.hbase.client.Put; public class HbaseAddEdtDel {  public static Configuration configuration=null;  static {  configuration = HBaseConfiguration.create();  configuration.set("hbase.master", "192.168.0.201:60000");  configuration.set("hbase.zookeeper.quorum","192.168.0.201,192.168.0.202,192.168.0.203");    configuration.set("hbase.zookeeper.property.clientPort", "2181");         }     public static void main(String[] args) throws Exception {            HBaseAdmin admin = new HBaseAdmin(configuration);                   if (admin.tableExists("riapguh")) {            System.out.println("刪除 table");            admin.disableTable("riapguh");            admin.deleteTable("riapguh");        }                     //創(chuàng)建riapguh表        System.out.println("創(chuàng)建 table");        HTableDescriptor tableDescripter = new HTableDescriptor("riapguh".getBytes());//創(chuàng)建表        tableDescripter.addFamily(new HColumnDescriptor("user"));//創(chuàng)建列簇user        tableDescripter.addFamily(new HColumnDescriptor("dpt"));//創(chuàng)建列簇dpt        admin.createTable(tableDescripter);               HTable table = new HTable(configuration, "riapguh");         //插入數(shù)據(jù)       System.out.println("add riapguh data");      List<Put> putuser = new ArrayList<Put>();                   Put user1 = new Put(new String("用戶A").getBytes());       //寫入用戶員信息       user1.add(new String("user").getBytes(), new String("user_code").getBytes(), new String("u_0001").getBytes());       user1.add(new String("user").getBytes(), new String("user_name").getBytes(), new String("u_用戶A").getBytes());             //寫入部門信息       user1.add(new String("dpt").getBytes(), new String("dpt_code").getBytes(), new String("d_001").getBytes());       user1.add(new String("dpt").getBytes(), new String("dpt_name").getBytes(), new String("d_部門A").getBytes());       putuser.add(user1);                     Put user2 = new Put(new String("用戶B").getBytes());       //寫入用戶員信息       user2.add(new String("user").getBytes(), new String("user_code").getBytes(), new String("u_0002").getBytes());       user2.add(new String("user").getBytes(), new String("user_name").getBytes(), new String("u_用戶B").getBytes());             //寫入部門信息       user2.add(new String("dpt").getBytes(), new String("dpt_code").getBytes(), new String("d_002").getBytes());       user2.add(new String("dpt").getBytes(), new String("dpt_name").getBytes(), new String("d_部門B").getBytes());       putuser.add(user2);                       Put user3 = new Put(new String("用戶C").getBytes());       //寫入用戶員信息       user3.add(new String("user").getBytes(), new String("user_code").getBytes(), new String("u_0003").getBytes());       user3.add(new String("user").getBytes(), new String("user_name").getBytes(), new String("u_用戶C").getBytes());             //寫入部門信息       user3.add(new String("dpt").getBytes(), new String("dpt_code").getBytes(), new String("d_003").getBytes());       user3.add(new String("dpt").getBytes(), new String("dpt_name").getBytes(), new String("d_部門C").getBytes());       putuser.add(user3);          table.put(putuser);      table.flushCommits();           //更新用戶B      Put updateb = new Put(new String("用戶B").getBytes());     //寫入用戶員信息      updateb.add(new String("user").getBytes(), new String("user_code").getBytes(), new String("u_000xsx").getBytes());      updateb.add(new String("user").getBytes(), new String("user_name").getBytes(), new String("u_用戶xsx").getBytes());        //寫入部門信息      updateb.add(new String("dpt").getBytes(), new String("dpt_code").getBytes(), new String("d_00xsx").getBytes());      updateb.add(new String("dpt").getBytes(), new String("dpt_name").getBytes(), new String("d_部門xsx").getBytes());      table.put(updateb);           table.flushCommits();      //HBaseBasic.selectByRowKey("riapguh");           System.out.println("-------------刪除用戶C---------------------");      //刪除用戶C      //able.delete(new Delete(new String("用戶C").getBytes()));      List<Delete> deld = new ArrayList<Delete>();      deld.add(new Delete(new String("用戶C").getBytes()));      table.delete(deld);           table.flushCommits();      //HBaseBasic.selectByRowKey("riapguh");    } }

“hbase中創(chuàng)建表、插入數(shù)據(jù),更新數(shù)據(jù),刪除數(shù)據(jù)的操作”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

當(dāng)前名稱:hbase中創(chuàng)建表、插入數(shù)據(jù),更新數(shù)據(jù),刪除數(shù)據(jù)的操作
URL標(biāo)題:http://muchs.cn/article12/ipgdgc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷、響應(yīng)式網(wǎng)站、域名注冊(cè)做網(wǎng)站、品牌網(wǎng)站建設(shè)關(guān)鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)