亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

hbase 基本開發-插入表

發布時間:2020-06-17 17:46:10 來源:網絡 閱讀:913 作者:JUN_LJ 欄目:大數據

創建maven項目

pom.xml文件內容: 3個依賴包 hbase-client hadoop-hdfs jdk.tools


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>mjj.hbase</groupId>

  <artifactId>test-10</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  <dependencies>

        <dependency>

            <groupId>org.apache.hbase</groupId>

            <artifactId>hbase-client</artifactId>

            <version>2.0.0</version>

        </dependency>

        <dependency>

            <groupId>org.apache.hadoop</groupId>

            <artifactId>hadoop-hdfs</artifactId>

            <version>2.8.0</version>

        </dependency>

        <dependency>

            <groupId>jdk.tools</groupId>

            <artifactId>jdk.tools</artifactId>

            <version>1.8</version>

            <scope>system</scope>

            <systemPath>C:\Program Files\Java\jdk1.8.0_151\lib\tools.jar</systemPath>

        </dependency>

    </dependencies>

</project>


連接hbase的兩種方法:

配置法(不一定要按圖配置,程序會默認去讀classpath下的配置文件,可以通過System.out.println(ClassLoader.getSystemResource("").toString());獲取)

1 在main文件夾下,建立resources文件夾,在resources文件夾下建立hbase文件,hbase文件夾下放hbase-site.xml配置文件(主要用到里面的zookeeper配置信息)

hbase 基本開發-插入表

配置文件主要內容如下:

hbase-site.xml

<property>

 <name>hbase.zookeeper.quorum</name>

  <value>192.168.50.1071</value>

 </property>

 <property>

  <name>hbase.zookeeper.property.clientPort</name>  

  <value>2181</value>

 </property>


代碼:

package myHbase;


import java.io.IOException;


import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.Cell;

import org.apache.hadoop.hbase.Cell.Type;

import org.apache.hadoop.hbase.CellBuilder;

import org.apache.hadoop.hbase.CellBuilderFactory;

import org.apache.hadoop.hbase.CellBuilderType;

import org.apache.hadoop.hbase.HBaseConfiguration;

import org.apache.hadoop.hbase.TableName;

import org.apache.hadoop.hbase.client.Connection;

import org.apache.hadoop.hbase.client.ConnectionFactory;

import org.apache.hadoop.hbase.client.HBaseAdmin;

import org.apache.hadoop.hbase.client.Put;

import org.apache.hadoop.hbase.client.Table;

import org.apache.hadoop.hbase.util.Bytes;


public class SimpleTest {


public static void main(String[] args) throws IOException {

// TODO Auto-generated method stub

Configuration hBaseConfig = HBaseConfiguration.create();

HBaseAdmin.available(hBaseConfig);

Connection connection = ConnectionFactory.createConnection(hBaseConfig);


TableName table1 = TableName.valueOf("test");

Table table = connection.getTable(table1);


CellBuilder cb = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);

cb.setRow(Bytes.toBytes("row3"));

cb.setFamily(Bytes.toBytes("cf"));

cb.setQualifier("qualifier1".getBytes());

cb.setValue(Bytes.toBytes("mjj2"));

cb.setType(Type.Put);

Cell cell = cb.build();


Put p = new Put(Bytes.toBytes("row3"));

p.add(cell);

table.put(p);


connection.close();

}


}


配置不正確報錯(zookeeper的連接丟失): 

Exception in thread "main" org.apache.hadoop.hbase.MasterNotRunningException: org.apache.hadoop.hbase.MasterNotRunningException: java.io.IOException: org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /hbase/master


代碼里設定zookeeper:

package myHbase;


import java.io.IOException;


import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.Cell;

import org.apache.hadoop.hbase.Cell.Type;

import org.apache.hadoop.hbase.CellBuilder;

import org.apache.hadoop.hbase.CellBuilderFactory;

import org.apache.hadoop.hbase.CellBuilderType;

import org.apache.hadoop.hbase.HBaseConfiguration;

import org.apache.hadoop.hbase.TableName;

import org.apache.hadoop.hbase.client.Connection;

import org.apache.hadoop.hbase.client.ConnectionFactory;

import org.apache.hadoop.hbase.client.HBaseAdmin;

import org.apache.hadoop.hbase.client.Put;

import org.apache.hadoop.hbase.client.Table;

import org.apache.hadoop.hbase.util.Bytes;


public class SimpleTest {


public static void main(String[] args) throws IOException {

// TODO Auto-generated method stub

Configuration hBaseConfig = HBaseConfiguration.create();

hBaseConfig.set("hbase.zookeeper.quorum", "192.168.50.107");

hBaseConfig.set("hbase.zookeeper.property.clientPort", "2181");

HBaseAdmin.available(hBaseConfig);

Connection connection = ConnectionFactory.createConnection(hBaseConfig);


TableName table1 = TableName.valueOf("test");

Table table = connection.getTable(table1);


CellBuilder cb = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);

cb.setRow(Bytes.toBytes("row3"));

cb.setFamily(Bytes.toBytes("cf"));

cb.setQualifier("qualifier1".getBytes());

cb.setValue(Bytes.toBytes("mjj2"));

cb.setType(Type.Put);

Cell cell = cb.build();


Put p = new Put(Bytes.toBytes("row3"));

p.add(cell);

table.put(p);


connection.close();

}


}


重要: windows上一定要配置/etc/hosts. 添加一條 192.168.50.107 rhel  -------其中rhel 為 hbase機子的主機名。原因未知。

否則報錯: 

Exception in thread "main" org.apache.hadoop.hbase.MasterNotRunningException: org.apache.hadoop.hbase.MasterNotRunningException: java.net.UnknownHostException: can not resolve rhel,16000,1530027948780



向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

洪江市| 临澧县| 鸡东县| 汨罗市| 莒南县| 平遥县| 望城县| 南昌县| 中宁县| 福清市| 皋兰县| 崇州市| 万全县| 永丰县| 湖南省| 米泉市| 枣强县| 深圳市| 高雄市| 邢台县| 吉林省| 新安县| 竹溪县| 高州市| 赤水市| 重庆市| 叶城县| 千阳县| 桂阳县| 彭泽县| 邯郸市| 日土县| 绥宁县| 巴林左旗| 和政县| 石泉县| 湘阴县| 辽宁省| 云林县| 金乡县| 长治县|