iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >按条件查询与删除数据-----HBase(伪分布)学习笔记
  • 948
分享到

按条件查询与删除数据-----HBase(伪分布)学习笔记

2024-04-02 19:04:59 948人浏览 泡泡鱼
摘要

                 public stat

        

 
  
  
 public static void deleteRows(String tablename,String RowKey){
         HTable h=null;
         HBaseAdmin ha=null;
         Get get=new Get(Bytes.toBytes(RowKey));
             try{
                 ha=new HBaseAdmin(config);
                 if(ha.tableExists(tablename)){
                 h=new HTable(config,tablename);
                 Delete d=new Delete(Bytes.toBytes(RowKey));
                 if(h.exists(get)){
                     h.delete(d);
                     System.out.println("删除成功");
                     }else{
                         System.out.println("滚犊子!!!");
                     }
                     }else{
                 System.out.println("表呢?你的表那!!");
             }
         }catch(Exception e){
             e.printStackTrace();
         }finally{
             try {
                h.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
         }
     }
 
 
 
  
  
  
 public static void deleteRow(String tablename,String RowKey,String family,String qualifier){
        HTable h=null;
         try {
                h=new HTable(config,tablename);
                Delete d=new Delete(Bytes.toBytes(RowKey));
                d.deleteColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier));
                h.delete(d);
                System.out.println("删除成功!");  
            } catch (IOException e) {
                e.printStackTrace();
            }finally{
                try {
                    h.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
         }
         
         
 
  
  
 @SuppressWarnings("deprecation")
public static void GetByParam(String tablename,String Family,String qualifier,String value){
        HTable h=null;
        ResultScanner rs=null;
             try {
                h=new HTable(config,tablename);
                Filter f=new SingleColumnValueFilter(Bytes.toBytes(Family),Bytes.toBytes(qualifier),CompareOp.EQUAL,Bytes.toBytes(value) );
                Scan scan=new Scan();
                scan.setFilter(f);
                scan.addColumn(Bytes.toBytes(Family),Bytes.toBytes(qualifier));
                rs=h.getScanner(scan);
                System.out.println("行     列簇     列名     值             时间戳");
                for (Result r : rs) {  
                for (KeyValue kv : r.raw()) {  
                    System.out.println(kv.getRowOffset()+"    "+Family+"       "+qualifier+"    "+new String(kv.getValue())+"    "+ kv.getTimestamp());
                }  
            }  
                } catch (IOException e) {
                    e.printStackTrace();
                }finally{
                    try{
                         rs.close();  
                         h.close();
                    }catch(Exception e){
                        e.printStackTrace();
                    }
                }
             }
             
             
 
  
  
 public static void get(String tablename,String rowKey,String Family,String qualifier)throws Exception{
         HConnection connection = HConnectionManager.createConnection(config);
         HTableInterface table = connection.getTable(TableName.valueOf(tablename));
             try {
                 System.out.println("开始获取------哔哔哔");
                 Get get=new Get(rowKey.getBytes());
                 get.addColumn(Family.getBytes(), qualifier.getBytes());
                 Result r=table.get(get);
                 for(KeyValue kv:r.raw())
                    {
                        System.out.println("您要查的值为"+new String(kv.getValue()));
                    }
                     } finally {
                        table.close();
                        connection.close();
                     } 
                 }


您可能感兴趣的文档:

--结束END--

本文标题: 按条件查询与删除数据-----HBase(伪分布)学习笔记

本文链接: https://www.lsjlt.com/news/36546.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作