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();
            }
        }
    } 
  • 相关阅读:
    python
    python
    python
    python
    python
    python
    python
    python
    [ThinkPHP] 从一个表中获得栏目对应的ID,从另一个表获得属于这些栏目的文章
    [thinkPHP] buildSql可以查看tp CURD操作对应的SQL
  • 原文地址:https://www.cnblogs.com/zhangzhongkun/p/11688580.html
Copyright © 2011-2022 走看看