zoukankan      html  css  js  c++  java
  • 共享

    import java.io.IOException;
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.hbase.*;
    import org.apache.hadoop.hbase.client.*;
    
    public class HbaseTest {
        public static Configuration configuration;
        public static Connection connection;
        public static Admin admin;
        public static void main(String[] args) {
            configuration = HBaseConfiguration.create();
            configuration.set("hbase.rootdir", "hdfs://localhost:9000/hbase");
            try {
                connection = ConnectionFactory.createConnection(configuration);
                admin = connection.getAdmin();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                insertRow("Student","003","name","","scofield");    
                insertRow("Student", "003", "score","English", "45");
                insertRow("Student", "003", "score","Math", "89");
                insertRow("Student", "003", "score","Computer", "100");
            } catch (IOException e) {
                e.printStackTrace();
            }
            close();
        }
        public static void insertRow(String tableName, String rowKey,String colFamily, String col, String val) throws IOException {
            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();
        }
        public static void close() {
            try {
                if (admin != null) {
                    admin.close();
                }
                if (null != connection) {
                    connection.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    } 
  • 相关阅读:
    hdu1238 Substrings
    CCF试题:高速公路(Targin)
    hdu 1269 迷宫城堡(Targin算法)
    hdu 1253 胜利大逃亡
    NYOJ 55 懒省事的小明
    HDU 1024 Max Sum Plus Plus
    HDU 1087 Super Jumping! Jumping! Jumping!
    HDU 1257 最少拦截系统
    HDU 1069 Monkey and Banana
    HDU 1104 Remainder
  • 原文地址:https://www.cnblogs.com/zhangzhongkun/p/11688580.html
Copyright © 2011-2022 走看看