zoukankan      html  css  js  c++  java
  • 统计表的行数。

    import java.io.IOException;
    
    
    public class E_getTableRowSum {
        public static Configuration configuration;
        public static Connection connection;
        public static Admin admin;
        
        /**
         * @param args
         * @throws IOException 
         */
        public static void main(String[] args) throws IOException {
            // TODO Auto-generated method stub
            getTableRows("student");
        }
        //建立连接
        public static void init(){
            configuration  = HBaseConfiguration.create();
            configuration.set("hbase.rootdir","hdfs://localhost:9000/hbase");
            try{
                connection = ConnectionFactory.createConnection(configuration);
                admin = connection.getAdmin();
            }catch (IOException e){
                e.printStackTrace();
            }
        }
        //关闭连接
        public static void close(){
            try{
                if(admin != null){
                    admin.close();
                }
                if(null != connection){
                    connection.close();
                }
            }catch (IOException e){
                e.printStackTrace();
            }
        }
        /*
         * E_
         */
        public static void getTableRows(String tablename) throws IOException {
            init();
            HTableDescriptor hTableDescriptors[] = admin.listTables();
            System.out.println("tablename:"+tablename);
            Table table = connection.getTable(TableName.valueOf(tablename));
            //创建一个空的Scan实例
            Scan scan1 = new Scan();
            //在行上获取遍历器
            ResultScanner scanner1 = table.getScanner(scan1);
            int count_rows=0;
            for (Result res : scanner1) {
                System.out.println(res);
                Cell[] cells = res.rawCells();
                for(Cell cell:cells){
                    count_rows+=1;
                }
            }
            //关闭释放资源
            System.out.println("count_rows:"+count_rows);
            scanner1.close();
            table.close();
            close();
        }
    
    }
  • 相关阅读:
    [恢]hdu 1548
    [恢]hdu 2102
    [恢]hdu 1238
    [恢]hdu 2564
    [恢]hdu 2565
    关于mmu,bootloader,dta以及各种乱七八糟
    总有那些让人XX的词语
    VS2005+SQL2005 Reporting Service动态绑定报表(Web)
    (已测试)在本地处理模式下将数据库数据源与 ReportViewer Web 服务器控件一起使用
    如何在单台计算机上安装 Reporting Services
  • 原文地址:https://www.cnblogs.com/MiraculousB/p/13958123.html
Copyright © 2011-2022 走看看