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();
            }
        }
    } 
  • 相关阅读:
    JAVA核心技术笔记总结--第14章 线程总结
    java核心技术笔记——第 9 章 集合
    Java核心技术笔记——第 8 章 泛型
    2.面向对象三大特征
    1.浅谈面向对象思想
    8.字符串
    7.数组
    6.调试程序
    5.流程控制语句
    4.运算符
  • 原文地址:https://www.cnblogs.com/zhangzhongkun/p/11688580.html
Copyright © 2011-2022 走看看