zoukankan      html  css  js  c++  java
  • 向已经创建好的表添加和删除指定的列族或列。

    import java.io.IOException;
    
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.hbase.HBaseConfiguration;
    import org.apache.hadoop.hbase.TableName;
    import org.apache.hadoop.hbase.client.Admin;
    import org.apache.hadoop.hbase.client.Connection;
    import org.apache.hadoop.hbase.client.ConnectionFactory;
    import org.apache.hadoop.hbase.client.Put;
    import org.apache.hadoop.hbase.client.Table;
    
    
    public class C_insertRows {
        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
            insertRow("student", "2015001", "info", "S_name", "Zhangsan");
            insertRow("student", "2015001", "info", "S_sex", "male");
            insertRow("student", "2015001", "info", "S_age", "23");
            insertRow("student", "2015002", "info", "S_name", "Mary");
            insertRow("student", "2015002", "info", "S_sex", "female");
            insertRow("student", "2015002", "info", "S_age", "22");
            insertRow("student", "2015003", "info", "S_name", "Lisi");
            insertRow("student", "2015003", "info", "S_sex", "male");
            insertRow("student", "2015003", "info", "S_age", "20");
            insertRow("SC", "2015001_123001", "SC_score", "", "86");
            insertRow("SC", "2015001_123003", "SC_score", "", "69");
            insertRow("SC", "2015002_123002", "SC_score", "", "77");
            insertRow("SC", "2015002_123003", "SC_score", "", "99");
            insertRow("SC", "2015003_123001", "SC_score", "", "98");
            insertRow("SC", "2015003_123002", "SC_score", "", "95");
            insertRow("Course", "123001", "info", "C_Name", "Math");
            insertRow("Course", "123001", "info", "C_Credit", "2.0");
            insertRow("Course", "123002", "info", "C_Name", "Computer Science");
            insertRow("Course", "123002", "info", "C_Credit", "5.0");
            insertRow("Course", "123003", "info", "C_Name", "English");
            insertRow("Course", "123003", "info", "C_Credit", "3.0");
            B_getAllData show = new B_getAllData();
            show.getTableData("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();
            }
        }
    
        //C_
        public static void insertRow(String tableName,String rowKey,String colFamily,String col,String val) throws IOException {
            init();
            Table table = connection.getTable(TableName.valueOf(tableName));
            Put put = new Put(rowKey.getBytes());
            put.addColumn(colFamily.getBytes(), col.getBytes(), val.getBytes());
            table.put(put);
            table.close();
            close();
        }
    }
  • 相关阅读:
    Mac安装LightGBM
    用于视频超分辨率的可变形三维卷积
    ORB-SLAM3 单目地图初始化(终结篇)
    重用地图的单目视觉惯导SLAM系统
    2020,我的秋招感悟!
    超详细解读ORB-SLAM3单目初始化(下篇)
    基于改进的点对特征的6D位姿估计
    深入研究自监督单目深度估计:Monodepth2
    ORB-SLAM3 细读单目初始化过程(上)
    基于视觉和惯性传感器的移动机器人手遥操作系统
  • 原文地址:https://www.cnblogs.com/MiraculousB/p/13958119.html
Copyright © 2011-2022 走看看