Get started with the HBase programming API put

Source: Internet
Author: User
Tags ssh secure shell

[email protected] conf]$ cat Regionservers
Hadoopmaster
HadoopSlave1
HadoopSlave2

<configuration>
<property>
<name>hbase.zookeeper.quorum</name>
<value>HadoopMaster,HadoopSlave1,HadoopSlave2</value>
</property>
<property>
<name>hbase.rootdir</name>
<value>hdfs://HadoopMaster:9000/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.tmp.dir</name>
<value>/home/hadoop/data/hbase-1.2.3/tmp</value>
</property>
<property>
<name>zookeeper.znode.parent</name>
<value>/hbase</value>
</property>
</configuration>

Export java_home=/home/hadoop/app/jdk1.7.0_79
Export Hbase_manages_zk=false

HBase (main):002:0> create ' test_table ', ' F '

Package zhouls.bigdata.HbaseProject.Test1;

Import org.apache.hadoop.conf.Configuration;
Import org.apache.hadoop.hbase.HBaseConfiguration;
Import Org.apache.hadoop.hbase.TableName;
Import org.apache.hadoop.hbase.client.HTable;
Import Org.apache.hadoop.hbase.client.Put;
Import org.apache.hadoop.hbase.util.Bytes;


public class Hbasetest {

public static void Main (string[] args) throws Exception {
htable table = new Htable (GetConfig (), tablename.valueof ("test_table"));//table name is test_table
Put put = new put (Bytes.tobytes ("row_01"));//Line key is row_01
Put.add (Bytes.tobytes ("F"), Bytes.tobytes ("col"), Bytes.tobytes ("Maizi"));//column cluster is f, column modifier is col, value is Maizi
Table.put (Put);
Table.close ();
}

public static Configuration GetConfig () {
Configuration configuration = new configuration ();
Conf.set ("Hbase.rootdir", "hdfs:hadoopmaster:9000/hbase");
Configuration.set ("Hbase.zookeeper.quorum", "hadoopmaster:2181,hadoopslave1:2181,hadoopslave2:2181");
return configuration;
}
}

2016-12-10 11:05:45,077 INFO [Org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper]-Process identifier= Hconnection-0x5fc2fc59 Connecting to ZooKeeper ensemble=hadoopmaster:2181,hadoopslave1:2181,hadoopslave2:2181
2016-12-10 11:05:45,115 INFO [Org.apache.zookeeper.ZooKeeper]-Client environment:zookeeper.version=3.4.6-1569965, Built on 02/20/2014 09:09 GMT
2016-12-10 11:05:45,115 INFO [Org.apache.zookeeper.ZooKeeper]-Client environment:host.name=win-bqobv63obnm
2016-12-10 11:05:45,115 INFO [Org.apache.zookeeper.ZooKeeper]-Client environment:java.version=1.7.0_51
2016-12-10 11:05:45,115 INFO [Org.apache.zookeeper.ZooKeeper]-Client environment:java.vendor=oracle Corporation
2016-12-10 11:05:45,116 INFO [Org.apache.zookeeper.ZooKeeper]-Client environment:java.home=c:\program files\java\ Jdk1.7.0_51\jre
2016-12-10 11:05:45,116 INFO [Org.apache.zookeeper.ZooKeeper]-Client environment:java.class.path=d:\code\ Myeclipsejavacode\hbaseproject\bin;d:\software\hbase-1.2.3\lib\activation-1.1.jar;d:\software\hbase-1.2.3\lib\ Aopalliance-1.0.jar;d:\software\hbase-1.2.3\lib\apacheds-i18n-2.0.0-m15.jar;d:\software\hbase-1.2.3\lib\ Apacheds-kerberos-codec-2.0.0-m15.jar;d:\software\hbase-1.2.3\lib\api-asn1-api-1.0.0-m20.jar;d:\software\ Hbase-1.2.3\lib\api-util-1.0.0-m20.jar;d:\software\hbase-1.2.3\lib\asm-3.1.jar;d:\software\hbase-1.2.3\lib\ Avro-1.7.4.jar;d:\software\hbase-1.2.3\lib\commons-beanutils-1.7.0.jar;d:\software\hbase-1.2.3\lib\ Commons-beanutils-core-1.8.0.jar;d:\software\hbase-1.2.3\lib\commons-cli-1.2.jar;d:\software\hbase-1.2.3\lib\ Commons-codec-1.9.jar;d:\software\hbase-1.2.3\lib\commons-collections-3.2.2.jar;d:\software\hbase-1.2.3\lib\ Commons-compress-1.4.1.jar;d:\software\hbase-1.2.3\lib\commons-configuration-1.6.jar;d:\software\hbase-1.2.3\ Lib\commons-daemon-1.0.13.jar;d:\software\Hbase-1.2.3\lib\commons-digester-1.8.jar;d:\software\hbase-1.2.3\lib\commons-el-1.0.jar;d:\software\ Hbase-1.2.3\lib\commons-httpclient-3.1.jar;d:\software\hbase-1.2.3\lib\commons-io-2.4.jar;d:\software\ Hbase-1.2.3\lib\commons-lang-2.6.jar;d:\software\hbase-1.2.3\lib\commons-logging-1.2.jar;d:\software\ Hbase-1.2.3\lib\commons-math-2.2.jar;d:\software\hbase-1.2.3\lib\commons-math3-3.1.1.jar;d:\software\ Hbase-1.2.3\lib\commons-net-3.1.jar;d:\software\hbase-1.2.3\lib\disruptor-3.3.0.jar;d:\software\hbase-1.2.3\ Lib\findbugs-annotations-1.3.9-1.jar;d:\software\hbase-1.2.3\lib\guava-12.0.1.jar;d:\software\hbase-1.2.3\lib\ Guice-3.0.jar;d:\software\hbase-1.2.3\lib\guice-servlet-3.0.jar;d:\software\hbase-1.2.3\lib\ Hadoop-annotations-2.5.1.jar;d:\software\hbase-1.2.3\lib\hadoop-auth-2.5.1.jar;d:\software\hbase-1.2.3\lib\ Hadoop-client-2.5.1.jar;d:\software\hbase-1.2.3\lib\hadoop-common-2.5.1.jar;d:\software\hbase-1.2.3\lib\ Hadoop-hdfs-2.5.1.jar;d:\software\hbase-1.2.3\lib\hadoop-mapreduce-client-aPp-2.5.1.jar;d:\software\hbase-1.2.3\lib\hadoop-mapreduce-client-common-2.5.1.jar;d:\software\hbase-1.2.3\lib\ Hadoop-mapreduce-client-core-2.5.1.jar;d:\software\hbase-1.2.3\lib\hadoop-mapreduce-client-jobclient-2.5.1.jar ;D: \software\hbase-1.2.3\lib\hadoop-mapreduce-client-shuffle-2.5.1.jar;d:\software\hbase-1.2.3\lib\ Hadoop-yarn-api-2.5.1.jar;d:\software\hbase-1.2.3\lib\hadoop-yarn-client-2.5.1.jar;d:\software\hbase-1.2.3\lib \hadoop-yarn-common-2.5.1.jar;d:\software\hbase-1.2.3\lib\hadoop-yarn-server-common-2.5.1.jar;d:\software\ Hbase-1.2.3\lib\hbase-annotations-1.2.3.jar;d:\software\hbase-1.2.3\lib\hbase-annotations-1.2.3-tests.jar;d:\ Software\hbase-1.2.3\lib\hbase-client-1.2.3.jar;d:\software\hbase-1.2.3\lib\hbase-common-1.2.3.jar;d:\software \hbase-1.2.3\lib\hbase-common-1.2.3-tests.jar;d:\software\hbase-1.2.3\lib\hbase-examples-1.2.3.jar;d:\software \hbase-1.2.3\lib\hbase-external-blockcache-1.2.3.jar;d:\software\hbase-1.2.3\lib\ Hbase-hadoop2-compat-1.2.3.jar;d:\software\hbase-1.2.3\Lib\hbase-hadoop-compat-1.2.3.jar;d:\software\hbase-1.2.3\lib\hbase-it-1.2.3.jar;d:\software\hbase-1.2.3\lib\ Hbase-it-1.2.3-tests.jar;d:\software\hbase-1.2.3\lib\hbase-prefix-tree-1.2.3.jar;d:\software\hbase-1.2.3\lib\ Hbase-procedure-1.2.3.jar;d:\software\hbase-1.2.3\lib\hbase-protocol-1.2.3.jar;d:\software\hbase-1.2.3\lib\ Hbase-resource-bundle-1.2.3.jar;d:\software\hbase-1.2.3\lib\hbase-rest-1.2.3.jar;d:\software\hbase-1.2.3\lib\ Hbase-server-1.2.3.jar;d:\software\hbase-1.2.3\lib\hbase-server-1.2.3-tests.jar;d:\software\hbase-1.2.3\lib\ Hbase-shell-1.2.3.jar;d:\software\hbase-1.2.3\lib\hbase-thrift-1.2.3.jar;d:\software\hbase-1.2.3\lib\ Htrace-core-3.1.0-incubating.jar;d:\software\hbase-1.2.3\lib\httpclient-4.2.5.jar;d:\software\hbase-1.2.3\lib\ Httpcore-4.4.1.jar;d:\software\hbase-1.2.3\lib\jackson-core-asl-1.9.13.jar;d:\software\hbase-1.2.3\lib\ Jackson-jaxrs-1.9.13.jar;d:\software\hbase-1.2.3\lib\jackson-mapper-asl-1.9.13.jar;d:\software\hbase-1.2.3\lib \jackson-xc-1.9.13.jar;d:\software\hbase-1.2.3\lib\jamon-runtime-2.4.1.jar;d:\software\hbase-1.2.3\lib\jasper-compiler-5.5.23.jar;d:\software\ Hbase-1.2.3\lib\jasper-runtime-5.5.23.jar;d:\software\hbase-1.2.3\lib\javax.inject-1.jar;d:\software\ hbase-1.2.3\lib\java-xmlbuilder-0.4.jar;d:\software\hbase-1.2.3\lib\jaxb-api-2.2.2.jar;d:\software\hbase-1.2.3 \lib\jaxb-impl-2.2.3-1.jar;d:\software\hbase-1.2.3\lib\jcodings-1.0.8.jar;d:\software\hbase-1.2.3\lib\ Jersey-client-1.9.jar;d:\software\hbase-1.2.3\lib\jersey-core-1.9.jar;d:\software\hbase-1.2.3\lib\ Jersey-guice-1.9.jar;d:\software\hbase-1.2.3\lib\jersey-json-1.9.jar;d:\software\hbase-1.2.3\lib\ Jersey-server-1.9.jar;d:\software\hbase-1.2.3\lib\jets3t-0.9.0.jar;d:\software\hbase-1.2.3\lib\ Jettison-1.3.3.jar;d:\software\hbase-1.2.3\lib\jetty-6.1.26.jar;d:\software\hbase-1.2.3\lib\ Jetty-sslengine-6.1.26.jar;d:\software\hbase-1.2.3\lib\jetty-util-6.1.26.jar;d:\software\hbase-1.2.3\lib\ Joni-2.1.2.jar;d:\software\hbase-1.2.3\lib\jruby-complete-1.6.8.jar;d:\software\hbase-1.2.3\Lib\jsch-0.1.42.jar;d:\software\hbase-1.2.3\lib\jsp-2.1-6.1.14.jar;d:\software\hbase-1.2.3\lib\ Jsp-api-2.1-6.1.14.jar;d:\software\hbase-1.2.3\lib\junit-4.12.jar;d:\software\hbase-1.2.3\lib\ Leveldbjni-all-1.8.jar;d:\software\hbase-1.2.3\lib\libthrift-0.9.3.jar;d:\software\hbase-1.2.3\lib\ Log4j-1.2.17.jar;d:\software\hbase-1.2.3\lib\metrics-core-2.2.0.jar;d:\software\hbase-1.2.3\lib\ Netty-all-4.0.23.final.jar;d:\software\hbase-1.2.3\lib\paranamer-2.3.jar;d:\software\hbase-1.2.3\lib\ Protobuf-java-2.5.0.jar;d:\software\hbase-1.2.3\lib\servlet-api-2.5.jar;d:\software\hbase-1.2.3\lib\ Servlet-api-2.5-6.1.14.jar;d:\software\hbase-1.2.3\lib\slf4j-api-1.7.7.jar;d:\software\hbase-1.2.3\lib\ Slf4j-log4j12-1.7.5.jar;d:\software\hbase-1.2.3\lib\snappy-java-1.0.4.1.jar;d:\software\hbase-1.2.3\lib\ Spymemcached-2.11.6.jar;d:\software\hbase-1.2.3\lib\xmlenc-0.52.jar;d:\software\hbase-1.2.3\lib\xz-1.0.jar;d:\ Software\hbase-1.2.3\lib\zookeeper-3.4.6.jar
2016-12-10 11:05:45,118 INFO [Org.apache.zookeeper.ZooKeeper]-Client environment:java.library.path=c:\program Files \java\jdk1.7.0_51\bin; C:\Windows\Sun\Java\bin; C:\Windows\system32; C:\Windows; C:\ProgramData\Oracle\Java\javapath; C:\Python27\; C:\Python27\Scripts; C:\Windows\system32; C:\Windows; C:\Windows\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1.0\;D: \software\matlab r2013a\runtime\win64;d:\software\matlab r2013a\ Bin C:\Program Files (x86) \IDM computer solutions\ultracompare; C:\Program Files\java\jdk1.7.0_51\bin; C:\Program Files\java\jdk1.7.0_51\jre\bin;d:\software\apache-ant-1.9.0\bin; Hadoop_home\bin;d:\software\apache-maven-3.3.9\bin;d:\software\scala\bin;d:\software\scala\jre\bin;%mysql_home \bin;d:\software\mysql Server\mysql Server 5.0\bin;d:\software\apache-tomcat-7.0.69\bin;%c:\windows\system32;%c:\ Windows\syswow64;d:\software\ssh Secure Shell;.
2016-12-10 11:05:45,119 INFO [Org.apache.zookeeper.ZooKeeper]-Client environment:java.io.tmpdir=c:\users\admini~1\ Appdata\local\temp\
2016-12-10 11:05:45,120 INFO [Org.apache.zookeeper.ZooKeeper]-Client environment:java.compiler=<na>
2016-12-10 11:05:45,120 INFO [Org.apache.zookeeper.ZooKeeper]-Client environment:os.name=windows 7
2016-12-10 11:05:45,121 INFO [Org.apache.zookeeper.ZooKeeper]-Client environment:os.arch=amd64
2016-12-10 11:05:45,121 INFO [Org.apache.zookeeper.ZooKeeper]-Client environment:os.version=6.1
2016-12-10 11:05:45,131 INFO [Org.apache.zookeeper.ZooKeeper]-Client environment:user.name=administrator
2016-12-10 11:05:45,131 INFO [Org.apache.zookeeper.ZooKeeper]-Client environment:user.home=c:\users\administrator
2016-12-10 11:05:45,132 INFO [Org.apache.zookeeper.ZooKeeper]-Client environment:user.dir=d:\code\ Myeclipsejavacode\hbaseproject
2016-12-10 11:05:45,136 INFO [Org.apache.zookeeper.ZooKeeper]-Initiating client connection, connectstring= hadoopmaster:2181,hadoopslave1:2181,hadoopslave2:2181 sessiontimeout=180000 watcher=hconnection-0x5fc2fc590x0, quorum=hadoopmaster:2181,hadoopslave1:2181,hadoopslave2:2181, Baseznode=/hbase
2016-12-10 11:05:45,329 INFO [ORG.APACHE.ZOOKEEPER.CLIENTCNXN]-Opening socket connection to server hadoopmaster/ 192.168.80.10:2181. Won't attempt to authenticate using SASL (unknown error)
2016-12-10 11:05:45,365 INFO [ORG.APACHE.ZOOKEEPER.CLIENTCNXN]-Socket connection established to hadoopmaster/ 192.168.80.10:2181, initiating session
2016-12-10 11:05:45,421 INFO [ORG.APACHE.ZOOKEEPER.CLIENTCNXN]-Session establishment complete on server hadoopmaster/ 192.168.80.10:2181, SessionID = 0x1582587a9550008, negotiated timeout = 40000
2016-12-10 11:05:47,266 INFO [org.apache.hadoop.hbase.client.connectionmanager$hconnectionimplementation]-Closing Zookeeper sessionid=0x1582587a9550008
2016-12-10 11:05:47,275 INFO [Org.apache.zookeeper.ZooKeeper]-session:0x1582587a9550008 closed
2016-12-10 11:05:47,275 INFO [ORG.APACHE.ZOOKEEPER.CLIENTCNXN]-Eventthread shut down

The put core code for getting started with the HBase programming API

Package zhouls.bigdata.HbaseProject.Test1;

Import org.apache.hadoop.conf.Configuration;
Import org.apache.hadoop.hbase.HBaseConfiguration;
Import Org.apache.hadoop.hbase.TableName;
Import org.apache.hadoop.hbase.client.HTable;
Import Org.apache.hadoop.hbase.client.Put;
Import org.apache.hadoop.hbase.util.Bytes;


public class Hbasetest {

public static void Main (string[] args) throws Exception {
htable table = new Htable (GetConfig (), tablename.valueof ("test_table"));//table name is test_table
Put put = new put (Bytes.tobytes ("row_03"));//Line key is row_01
Put.add (Bytes.tobytes ("F"), Bytes.tobytes ("name"), Bytes.tobytes ("Andy3"));//column cluster is f, column modifier is name, value is Andy3
Table.put (Put);
Table.close ();
}

public static Configuration GetConfig () {
Configuration configuration = new configuration ();
Conf.set ("Hbase.rootdir", "hdfs:hadoopmaster:9000/hbase");
Configuration.set ("Hbase.zookeeper.quorum", "hadoopmaster:2181,hadoopslave1:2181,hadoopslave2:2181");
return configuration;
}
}

Get started with the HBase programming API put

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.