首页 > 其他分享 >今天继续补实验

今天继续补实验

时间:2024-12-04 23:10:51浏览次数:5  
标签:String hadoop 实验 今天 org apache import hbase 继续

package Main;

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 main {

    public static Configuration configuration;
    public static Connection connection;
    public static Admin admin;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        configuration  = HBaseConfiguration.create();
        configuration.set("hbase.rootdir","hdfs://127.0.0.1:8020/hbase");
        try{
            connection = ConnectionFactory.createConnection(configuration);
            admin = connection.getAdmin();
        }catch (IOException e){
            e.printStackTrace();
        }
        try {
            insertRow("student","scofield","score","English","45");
            insertRow("student","scofield","score","Math","89");
            insertRow("student","scofield","score","Computer","100");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            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();
        }
    }
}
package Main;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
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.Get;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;

public class main {

    public static Configuration configuration;
    public static Connection connection;
    public static Admin admin;

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        configuration = HBaseConfiguration.create();

        configuration.set("hbase.rootdir", "hdfs://127.0.0.1:8020/hbase");

        try {
            connection = ConnectionFactory.createConnection(configuration);
            admin = connection.getAdmin();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            getData("student", "scofield", "score", "English");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        close();
    }

    public static void getData(String tableName, String rowKey, String colFamily,
                               String col) throws IOException {
        Table table = connection.getTable(TableName.valueOf(tableName));
        Get get = new Get(rowKey.getBytes());
        get.addColumn(colFamily.getBytes(), col.getBytes());
        Result result = table.get(get);
        showCell(result);
        table.close();
    }

    public static void showCell(Result result) {
        Cell[] cells = result.rawCells();
        for (Cell cell : cells) {
            System.out.println("RowName:" + new String(CellUtil.cloneRow(cell)) + " ");
   System.out.println("Timetamp:" + cell.getTimestamp() + " ");
            System.out.println("column Family:" + new String(CellUtil.cloneFamily(cell)) + " ");
            System.out.println("row Name:" + new String(CellUtil.cloneQualifier(cell)) + " ");
            System.out.println("value:" + new String(CellUtil.cloneValue(cell)) + " ");
        }
    }

    public static void close() {
        try {
            if (admin != null) {
                admin.close();
            }
            if (null != connection) {
                connection.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

 

标签:String,hadoop,实验,今天,org,apache,import,hbase,继续
From: https://www.cnblogs.com/muzhaodi/p/18587452

相关文章

  • 实验1-5编程
    实验1floor,ceil#向下取整,向上取整a,b,c=map(int,input().split())a,b=map(int,input().split())#得到输入的去空格的int型数值,分别赋予a,bx=complex(a,b)#x用来表示一个复数,比如complex(1,2)实为1+2iwhile1:#当有输入时a,b,c=map(int,input().split())y=......
  • 实验5 继承和多态
    1.实验任务1publisher.hpp1#pragmaonce23#include<iostream>4#include<string>56usingstd::cout;7usingstd::endl;8usingstd::string;910//Publisher11classPublisher{12public:13Publisher(conststring&s=......
  • 实验5 继承和多态
    3.pets.hpp#pragmaonce#include<iostream>#include<string>usingnamespacestd;classMachinePets{public:MachinePets(conststrings);virtualstringtalk()const=0;stringget_nickname();private:stringnickname;}......
  • 20222325 2024-2025-1 《网络与系统攻防技术》实验八实验报告
    1.实验内容(1)Web前端HTML能正常安装、启停Apache。理解HTML,理解表单,理解GET与POST方法,编写一个含有表单的HTML(2)Web前端javascipt理解JavaScript的基本功能,理解DOM在(1)的基础上,编写JavaScript验证用户名、密码的规则。在用户点击登陆按钮后回显“欢迎+输入的用户名”尝试注......
  • 实验5 继承和多态
    实验任务3源代码:pets.hpp1#pragmaonce23#include<iostream>4#include<string>56usingnamespacestd;7classMachinePets{8public:9MachinePets(conststring&s);10stringget_nickname()const;11......
  • 实验5
    实验任务3: 1#pragmaonce2#include<iostream>3usingnamespacestd;4classMachinePets{5stringnickname;6public:7MachinePets(conststring&s){8nickname=s;9}10stringget_nicknam......
  • 实验五
    task1.1#include<stdio.h>2#defineN53voidinput(intx[],intn);4voidoutput(intx[],intn);5voidfind_min_max(intx[],intn,int*pmin,int*pmax);67intmain()8{9inta[N];10intmin,max;11printf("录入%d个数据......
  • 实验5 继承和多态
    实验任务3:task3.cpp:1#include<iostream>2#include<vector>3#include"pets.hpp"45voidtest(){6usingnamespacestd;78vector<MachinePets*>pets;910pets.push_back(newPetCats("miku"......
  • 实验5
    3:#pragmaonce#include<string>#include<iostream>usingnamespacestd;classMachinePets{public:stringnickname;public:MachinePets(conststring&s){nickname=s;}stringget_nickname(){return......
  • 20222407 2024-2025-1 《网络与系统攻防技术》实验八实验报告
    1.学习内容1.Web前端:负责开发用户所看到的内容。前端语言:HTML、JavaScript(JS):与Java没有关系,与JSP两回事,CSS。Web前端框架:Vue.js(中国人尤雨溪)、Bootstrap(Twitter)、Layui(极简单)、Element-UI(基于Vue.js2.0,饿了么)、Angular(Google)……2.Web后端:主要使用各种库,API,Web服务等技术搭建......