Hbase Client Test Case

Source: Internet
Author: User

Well, it's actually a simple hbase client Java operation

Hbasetestcase.java

Package Hbase;import Java.io.ioexception;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.client.get;import Org.apache.hadoop.hbase.client.hbaseadmin;import Org.apache.hadoop.hbase.client.htable;import Org.apache.hadoop.hbase.client.put;import Org.apache.hadoop.hbase.client.result;import Org.apache.hadoop.hbase.client.resultscanner;import org.apache.hadoop.hbase.client.scan;/** * * <p> * Title: Hbasetestcase.java * Package HBase * </p> * <p> * description:hbase Client TestCase * <p> * @author T Om.  Cai * @created 2015-4-28 pm 9:14:01 * @version V1.0 * */public class Hbasetestcase {public static final String table_name = "Table1";p ublic static final String family_name = "Family1";p ublic static final String row_key = "Row1";p ublic Static V OID Main (string[] args) throws Exception {ConfiguratIon conf = Hbaseconfiguration.create ();//Locate to Hadoopconf.set ("Hbase.rootdir", "hdfs://192.168.80.100:9000/hbase");// The Hadoop address can also be configured as the hostname of the form conf.set ("Hbase.zookeeper.quorum", "192.168.80.100"); Hbaseadmin admin = new hbaseadmin (conf);//Add Table createtable (admin);//delete table//deletetable (admin); htable htable = new htable (conf, table_name);//Add Table record//addrecodes (htable);//Get Table record Getrecodes (htable);//Full table Scan table scantable (htable);} private static void Scantable (Htable htable) throws IOException {Scan scan = new Scan (); Resultscanner Rscanner = Htable.getscanner (scan); for (Result Result:rscanner) {byte[] is = Result.getvalue (family_name. GetBytes (), "qualifier". GetBytes ()); System.out.println (result+ "---->value:" +new String (BE));}} private static void Getrecodes (Htable htable) throws IOException {Get get = new Get (Row_key.getbytes ()); Result result = Htable.get (get); byte[] B = Result.getvalue (Family_name.getbytes (), "qualifier". GetBytes ()); System.out.println (New String (b));} private static void Addrecodes (Htable htable) Throws IOException {put put = new Put (Row_key.getbytes ());p Ut.add (Family_name.getbytes (), "qualifier". GetBytes (), " Value ". GetBytes ()); Htable.put (put);} private static void Deletetable (Hbaseadmin admin) throws IOException {admin.disabletable (table_name); Admin.deletetable (table_name);} private static void CreateTable (Hbaseadmin admin) throws IOException {if (!admin.tableexists (table_name)) { Htabledescriptor desc = new Htabledescriptor (table_name); Hcolumndescriptor family = new Hcolumndescriptor (family_name);d esc.addfamily (family); admin.createtable (desc);}}}

My personal website: http://www.caicongyang.com

My csdn blog address: Http://blog.csdn.net/caicongyang




Hbase Client Test Case

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.