我正在关注this link将数据插入我的hbase。我按照所有步骤编写了代码:
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
public class Startclass {
private static Configuration conf = HBaseConfiguration.create();
public static void addRecord(String tableName, String rowKey,
String family, String qualifier, String value) throws Exception {
try {
HTable table = new HTable(conf, tableName);
Put put = new Put(Bytes.toBytes(rowKey));
put.add(Bytes.toBytes(family), Bytes.toBytes(qualifier), Bytes
.toBytes(value));
table.put(put);
System.out.println("insert recored " + rowKey + " to table "
+ tableName + " ok.");
} catch (IOException e){
e.printStackTrace();
}
}
public static void main(String[] agrs) {
try {
String tablename = "hl7";
Startclass.addRecord(tablename, "zkb", "pd", "dob", "10121993");
Startclass.addRecord(tablename, "zkb", "pd", "id", "007");
Startclass.addRecord(tablename, "zkb", "obr", "id", "007");
Startclass.addRecord(tablename, "zkb", "obr", "testname", "healthec");
Startclass.addRecord(tablename, "abc", "pd", "dob", "02051993");
Startclass.addRecord(tablename, "abc", "pd", "id", "011");
Startclass.addRecord(tablename, "abc", "obr", "id", "011");
Startclass.addRecord(tablename, "abc", "obr", "testname", "matrix");
} catch (Exception e) {
e.printStackTrace();
}
}
}
但我的结果低于结果
16/11/18 16:55:04 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.4.5-cdh5.8.0--1, built on 06/16/2016 19:37 GMT
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:host.name=quickstart.cloudera
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:java.version=1.7.0_67
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:java.home=/usr/java/jdk1.7.0_67-cloudera/jre
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:java.class.path=/home/cloudera/workspace/HbaseJav/bin:/home/cloudera/workspace/HbaseJav/conf:/usr/lib/hadoop/client/avro.jar:/usr/lib/hadoop/client/commons-beanutils-core.jar:/usr/lib/hadoop/client/commons-beanutils.jar:/usr/lib/hadoop/client/commons-cli.jar:/usr/lib/hadoop/client/commons-codec.jar:/usr/lib/hadoop/client/commons-collections.jar:/usr/lib/hadoop/client/commons-compress.jar:/usr/lib/hadoop/client/commons-configuration.jar:/usr/lib/hadoop/client/commons-digester.jar:/usr/lib/hadoop/client/commons-httpclient.jar:/usr/lib/hadoop/client/commons-io.jar:/usr/lib/hadoop/client/commons-lang.jar:/usr/lib/hadoop/client/commons-logging.jar:/usr/lib/hadoop/client/commons-math3.jar:/usr/lib/hadoop/client/commons-net.jar:/usr/lib/hadoop/client/guava.jar:/usr/lib/hadoop/client/hadoop-annotations.jar:/usr/lib/hadoop/client/hadoop-auth.jar:/usr/lib/hadoop/client/hadoop-common.jar:/usr/lib/hadoop/client/hadoop-hdfs.jar:/usr/lib/hadoop/client/hadoop-mapreduce-client-app.jar:/usr/lib/hadoop/client/hadoop-mapreduce-client-common.jar:/usr/lib/hadoop/client/hadoop-mapreduce-client-core.jar:/usr/lib/hadoop/client/hadoop-mapreduce-client-jobclient.jar:/usr/lib/hadoop/client/hadoop-mapreduce-client-shuffle.jar:/usr/lib/hadoop/client/hadoop-yarn-api.jar:/usr/lib/hadoop/client/hadoop-yarn-client.jar:/usr/lib/hadoop/client/hadoop-yarn-common.jar:/usr/lib/hadoop/client/hadoop-yarn-server-common.jar:/usr/lib/hadoop/client/htrace-core4.jar:/usr/lib/hadoop/client/jetty-util.jar:/usr/lib/hadoop/client/jsr305.jar:/usr/lib/hadoop/client/log4j.jar:/usr/lib/hadoop/client/paranamer.jar:/usr/lib/hadoop/client/protobuf-java.jar:/usr/lib/hadoop/client/slf4j-api.jar:/usr/lib/hadoop/client/snappy-java.jar:/usr/lib/hadoop/client/xmlenc.jar:/usr/lib/hadoop/client/xz.jar:/usr/lib/hadoop/client/zookeeper.jar:/home/cloudera/lib/mrunit-0.9.0-incubating-hadoop2.jar:/home/cloudera/lib/junit-4.11.jar:/home/cloudera/lib/hamcrest-all-1.1.jar:/home/cloudera/hbase-0.92.1.jar:/usr/lib/hbase/lib/commons-configuration-1.6.jar:/usr/lib/hbase/lib/commons-lang-2.6.jar:/usr/lib/hbase/lib/commons-logging-1.2.jar:/usr/lib/hbase/lib/log4j-1.2.17.jar:/usr/lib/hbase/lib/slf4j-api-1.7.5.jar:/usr/lib/hbase/lib/slf4j-log4j12.jar:/usr/lib/hbase/lib/zookeeper.jar:/usr/lib/hadoop-0.20-mapreduce/hadoop-core-2.6.0-mr1-cdh5.8.0.jar:/usr/lib/hadoop-0.20-mapreduce/hadoop-core-mr1.jar
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=/tmp
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA>
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:os.name=Linux
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:os.version=2.6.32-573.el6.x86_64
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:user.name=cloudera
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:user.home=/home/cloudera
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:user.dir=/home/cloudera/workspace/HbaseJav
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=180000 watcher=hconnection
16/11/18 16:55:05 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is 6315@quickstart.cloudera
16/11/18 16:55:05 INFO zookeeper.ClientCnxn: Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
16/11/18 16:55:05 INFO zookeeper.ClientCnxn: Socket connection established, initiating session, client: /127.0.0.1:41539, server: localhost/127.0.0.1:2181
16/11/18 16:55:05 INFO zookeeper.ClientCnxn: Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x15876ebae4a0138, negotiated timeout = 60000
我还使用正确的列系列名称创建了 hbase 表。 我不知道我做错了什么。请帮忙。
答案 0 :(得分:1)
如果你跑了命令 创造&#39; hl7&#39;,&#39; pd&#39;&#39; obr&#39; 在运行此代码之前,没有办法,它不会在表中插入数据。 只有这种可能性是在传递错误的配置或HBase(安装) - 依赖(项目)不兼容的情况下。