First, install HBase.
Create a Java project to bring in the jar package for Lib in HBase
Then create a class
Package Sun_test_pig;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;import Org.apache.hadoop.hbase.util.bytes;public class HBaseTest {Stati C Configuration cfg=hbaseconfiguration.create (); public static void Creat (String tablename,string columnfamily) throws Exception {hbaseadmin admin = new Hbaseadmin (CFG); if (admin.tableexists (tablename)) {System.out.println ("table exists!"); System.exit (0); } else{htabledescriptor Tabledesc = new Htabledescriptor (tablename); Tabledesc.addfamily (New Hcolumndescriptor (columnfamily)); Admin.createtable (TABLEDESC); SYSTEM.OUT.PRINTLN ("CREATE Table success!"); }} public static void put (string tablename,string row, string columnfamily,string column,string data) throws Except Ion {htable table = new htable (CFG, tablename); Put P1=new put (bytes.tobytes (row)); P1.add (Bytes.tobytes (columnfamily), bytes.tobytes (column), bytes.tobytes (data)); Table.put (p1); System.out.println ("Put" "+row+" ', ' "+columnfamily+": "+column+" ', ' "+data+" ' "); public static void Get (String tablename,string row) throws ioexception{htable table=new htable (cfg,tabl ENAME); Get G=new Get (bytes.tobytes (row)); Result Result=table.get (g); System.out.println ("Get:" +result); }//Show all data through htable scan to get information about existing tables public static void scan (String tablename) throws Exception{htable table = new htable (CFG, tablename); Scan s = new scan (); Resultscanner rs = Table.getscanner (s); for (Result r:rs) {System.out.println ("Scan:" +r); }} public static Boolean delete (String tablename) throws ioexception{Hbaseadmin Admin=n EW hbaseadmin (CFG); if (admin.tableexists (tablename)) {try {admin.disabletabl E (tablename); Admin.deletetable (tablename); }catch (Exception ex) {ex.printstacktrace (); return false; }} return true; public static void Main (string [] agrs) {string tablename= "HBASE_TB"; String columnfamily= "CF"; try {hbasetest.creat (tablename, columnfamily); Hbasetest.put (tablename, "Row1", columnfamily, "CL1", "data"); Hbasetest.get (tablename, "Row1"); Hbasetest.scan (tablename); if (True==hbasetest.delete (tablename)) System.out.println ("Delete table:" +tablename+ "success!"); } catch (Exception e) {e.printstacktrace (); } }}
Eclipse Development HBase Program