zoukankan      html  css  js  c++  java
  • HBase编程 API入门系列之scan(客户端而言)(5)

       心得,写在前面的话,也许,中间会要多次执行,连接超时,多试试就好了。

     1 package zhouls.bigdata.HbaseProject.Test1;
     2 
     3 import javax.xml.transform.Result;
     4 
     5 import org.apache.hadoop.conf.Configuration;
     6 import org.apache.hadoop.hbase.HBaseConfiguration;
     7 import org.apache.hadoop.hbase.TableName;
     8 import org.apache.hadoop.hbase.client.Delete;
     9 import org.apache.hadoop.hbase.client.Get;
    10 import org.apache.hadoop.hbase.client.HTable;
    11 import org.apache.hadoop.hbase.client.Put;
    12 import org.apache.hadoop.hbase.client.ResultScanner;
    13 import org.apache.hadoop.hbase.client.Scan;
    14 import org.apache.hadoop.hbase.util.Bytes;
    15 
    16 public class HBaseTest {
    17     public static void main(String[] args) throws Exception {
    18         HTable table = new HTable(getConfig(),TableName.valueOf("test_table"));//表名是test_table
    19 //        Put put = new Put(Bytes.toBytes("row_04"));//行键是row_04
    20 //        put.add(Bytes.toBytes("f"),Bytes.toBytes("name"),Bytes.toBytes("Andy1"));//列簇是f,列修饰符是name,值是Andy0
    21 //        put.add(Bytes.toBytes("f2"),Bytes.toBytes("name"),Bytes.toBytes("Andy3"));//列簇是f2,列修饰符是name,值是Andy3
    22 //        table.put(put);
    23 //        table.close();
    24 
    25 //        Get get = new Get(Bytes.toBytes("row_04"));
    26 //        get.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("age"));如现在这样,不指定,默认把所有的全拿出来
    27 //        org.apache.hadoop.hbase.client.Result rest = table.get(get);
    28 //        System.out.println(rest.toString());
    29 //        table.close();
    30 
    31 //        Delete delete = new Delete(Bytes.toBytes("row_2"));
    32 //        delete.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("email"));
    33 //        delete.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("name"));
    34 //        table.delete(delete);
    35 //        table.close();
    36 
    37 //        Delete delete = new Delete(Bytes.toBytes("row_04"));
    38 ////    delete.deleteColumn(Bytes.toBytes("f"), Bytes.toBytes("name"));//deleteColumn是删除某一个列簇里的最新时间戳版本。
    39 //        delete.deleteColumns(Bytes.toBytes("f"), Bytes.toBytes("name"));//delete.deleteColumns是删除某个列簇里的所有时间戳版本。
    40 //        table.delete(delete);
    41 //        table.close();
    42 
    43 
    44         Scan scan = new Scan();
    45         ResultScanner rst = table.getScanner(scan);
    46         System.out.println(rst.toString());
    47         table.close();
    48     }
    49 
    50     public static Configuration getConfig(){
    51         Configuration configuration = new Configuration(); 
    52 //        conf.set("hbase.rootdir","hdfs:HadoopMaster:9000/hbase");
    53         configuration.set("hbase.zookeeper.quorum", "HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181");
    54         return configuration;
    55     }
    56 }

    2016-12-10 17:24:08,394 INFO [org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper] - Process identifier=hconnection-0x7a45682c connecting to ZooKeeper ensemble=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181
    2016-12-10 17:24:08,432 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
    2016-12-10 17:24:08,433 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:host.name=WIN-BQOBV63OBNM
    2016-12-10 17:24:08,434 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.version=1.7.0_51
    2016-12-10 17:24:08,435 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.vendor=Oracle Corporation
    2016-12-10 17:24:08,436 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.home=C:Program FilesJavajdk1.7.0_51jre
    2016-12-10 17:24:08,436 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.class.path=D:CodeMyEclipseJavaCodeHbaseProjectin;D:SoftWarehbase-1.2.3libactivation-1.1.jar;D:SoftWarehbase-1.2.3libaopalliance-1.0.jar;D:SoftWarehbase-1.2.3libapacheds-i18n-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapacheds-kerberos-codec-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapi-asn1-api-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libapi-util-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libasm-3.1.jar;D:SoftWarehbase-1.2.3libavro-1.7.4.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-1.7.0.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-core-1.8.0.jar;D:SoftWarehbase-1.2.3libcommons-cli-1.2.jar;D:SoftWarehbase-1.2.3libcommons-codec-1.9.jar;D:SoftWarehbase-1.2.3libcommons-collections-3.2.2.jar;D:SoftWarehbase-1.2.3libcommons-compress-1.4.1.jar;D:SoftWarehbase-1.2.3libcommons-configuration-1.6.jar;D:SoftWarehbase-1.2.3libcommons-daemon-1.0.13.jar;D:SoftWarehbase-1.2.3libcommons-digester-1.8.jar;D:SoftWarehbase-1.2.3libcommons-el-1.0.jar;D:SoftWarehbase-1.2.3libcommons-httpclient-3.1.jar;D:SoftWarehbase-1.2.3libcommons-io-2.4.jar;D:SoftWarehbase-1.2.3libcommons-lang-2.6.jar;D:SoftWarehbase-1.2.3libcommons-logging-1.2.jar;D:SoftWarehbase-1.2.3libcommons-math-2.2.jar;D:SoftWarehbase-1.2.3libcommons-math3-3.1.1.jar;D:SoftWarehbase-1.2.3libcommons-net-3.1.jar;D:SoftWarehbase-1.2.3libdisruptor-3.3.0.jar;D:SoftWarehbase-1.2.3libfindbugs-annotations-1.3.9-1.jar;D:SoftWarehbase-1.2.3libguava-12.0.1.jar;D:SoftWarehbase-1.2.3libguice-3.0.jar;D:SoftWarehbase-1.2.3libguice-servlet-3.0.jar;D:SoftWarehbase-1.2.3libhadoop-annotations-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-auth-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-hdfs-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-app-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-core-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-jobclient-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-shuffle-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-api-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-server-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-client-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-examples-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-external-blockcache-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop2-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-prefix-tree-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-procedure-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-protocol-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-resource-bundle-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-rest-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-shell-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-thrift-1.2.3.jar;D:SoftWarehbase-1.2.3libhtrace-core-3.1.0-incubating.jar;D:SoftWarehbase-1.2.3libhttpclient-4.2.5.jar;D:SoftWarehbase-1.2.3libhttpcore-4.4.1.jar;D:SoftWarehbase-1.2.3libjackson-core-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-jaxrs-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-mapper-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-xc-1.9.13.jar;D:SoftWarehbase-1.2.3libjamon-runtime-2.4.1.jar;D:SoftWarehbase-1.2.3libjasper-compiler-5.5.23.jar;D:SoftWarehbase-1.2.3libjasper-runtime-5.5.23.jar;D:SoftWarehbase-1.2.3libjavax.inject-1.jar;D:SoftWarehbase-1.2.3libjava-xmlbuilder-0.4.jar;D:SoftWarehbase-1.2.3libjaxb-api-2.2.2.jar;D:SoftWarehbase-1.2.3libjaxb-impl-2.2.3-1.jar;D:SoftWarehbase-1.2.3libjcodings-1.0.8.jar;D:SoftWarehbase-1.2.3libjersey-client-1.9.jar;D:SoftWarehbase-1.2.3libjersey-core-1.9.jar;D:SoftWarehbase-1.2.3libjersey-guice-1.9.jar;D:SoftWarehbase-1.2.3libjersey-json-1.9.jar;D:SoftWarehbase-1.2.3libjersey-server-1.9.jar;D:SoftWarehbase-1.2.3libjets3t-0.9.0.jar;D:SoftWarehbase-1.2.3libjettison-1.3.3.jar;D:SoftWarehbase-1.2.3libjetty-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-sslengine-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-util-6.1.26.jar;D:SoftWarehbase-1.2.3libjoni-2.1.2.jar;D:SoftWarehbase-1.2.3libjruby-complete-1.6.8.jar;D:SoftWarehbase-1.2.3libjsch-0.1.42.jar;D:SoftWarehbase-1.2.3libjsp-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjsp-api-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjunit-4.12.jar;D:SoftWarehbase-1.2.3libleveldbjni-all-1.8.jar;D:SoftWarehbase-1.2.3liblibthrift-0.9.3.jar;D:SoftWarehbase-1.2.3liblog4j-1.2.17.jar;D:SoftWarehbase-1.2.3libmetrics-core-2.2.0.jar;D:SoftWarehbase-1.2.3lib etty-all-4.0.23.Final.jar;D:SoftWarehbase-1.2.3libparanamer-2.3.jar;D:SoftWarehbase-1.2.3libprotobuf-java-2.5.0.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5-6.1.14.jar;D:SoftWarehbase-1.2.3libslf4j-api-1.7.7.jar;D:SoftWarehbase-1.2.3libslf4j-log4j12-1.7.5.jar;D:SoftWarehbase-1.2.3libsnappy-java-1.0.4.1.jar;D:SoftWarehbase-1.2.3libspymemcached-2.11.6.jar;D:SoftWarehbase-1.2.3libxmlenc-0.52.jar;D:SoftWarehbase-1.2.3libxz-1.0.jar;D:SoftWarehbase-1.2.3libzookeeper-3.4.6.jar
    2016-12-10 17:24:08,439 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.library.path=C:Program FilesJavajdk1.7.0_51in;C:WindowsSunJavain;C:Windowssystem32;C:Windows;C:ProgramDataOracleJavajavapath;C:Python27;C:Python27Scripts;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;D:SoftWareMATLAB R2013a untimewin64;D:SoftWareMATLAB R2013ain;C:Program Files (x86)IDM Computer SolutionsUltraCompare;C:Program FilesJavajdk1.7.0_51in;C:Program FilesJavajdk1.7.0_51jrein;D:SoftWareapache-ant-1.9.0in;HADOOP_HOMEin;D:SoftWareapache-maven-3.3.9in;D:SoftWareScalain;D:SoftWareScalajrein;%MYSQL_HOMEin;D:SoftWareMySQL ServerMySQL Server 5.0in;D:SoftWareapache-tomcat-7.0.69in;%C:WindowsSystem32;%C:WindowsSysWOW64;D:SoftWareSSH Secure Shell;.
    2016-12-10 17:24:08,442 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.io.tmpdir=C:UsersADMINI~1AppDataLocalTemp
    2016-12-10 17:24:08,443 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.compiler=<NA>
    2016-12-10 17:24:08,443 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.name=Windows 7
    2016-12-10 17:24:08,443 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.arch=amd64
    2016-12-10 17:24:08,444 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.version=6.1
    2016-12-10 17:24:08,444 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.name=Administrator
    2016-12-10 17:24:08,445 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.home=C:UsersAdministrator
    2016-12-10 17:24:08,445 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.dir=D:CodeMyEclipseJavaCodeHbaseProject
    2016-12-10 17:24:08,449 INFO [org.apache.zookeeper.ZooKeeper] - Initiating client connection, connectString=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181 sessionTimeout=180000 watcher=hconnection-0x7a45682c0x0, quorum=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181, baseZNode=/hbase
    2016-12-10 17:24:08,638 INFO [org.apache.zookeeper.ClientCnxn] - Opening socket connection to server HadoopMaster/192.168.80.10:2181. Will not attempt to authenticate using SASL (unknown error)
    2016-12-10 17:24:08,651 INFO [org.apache.zookeeper.ClientCnxn] - Socket connection established to HadoopMaster/192.168.80.10:2181, initiating session
    2016-12-10 17:24:08,688 INFO [org.apache.zookeeper.ClientCnxn] - Session establishment complete on server HadoopMaster/192.168.80.10:2181, sessionid = 0x15825dedcf4002b, negotiated timeout = 40000
    org.apache.hadoop.hbase.client.ClientScanner@23b804dd
    2016-12-10 17:24:10,158 INFO [org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation] - Closing zookeeper sessionid=0x15825dedcf4002b
    2016-12-10 17:24:10,166 INFO [org.apache.zookeeper.ZooKeeper] - Session: 0x15825dedcf4002b closed
    2016-12-10 17:24:10,167 INFO [org.apache.zookeeper.ClientCnxn] - EventThread shut down

     

     1 package zhouls.bigdata.HbaseProject.Test1;
     2 
     3 import javax.xml.transform.Result;
     4 
     5 import org.apache.hadoop.conf.Configuration;
     6 import org.apache.hadoop.hbase.HBaseConfiguration;
     7 import org.apache.hadoop.hbase.TableName;
     8 import org.apache.hadoop.hbase.client.Delete;
     9 import org.apache.hadoop.hbase.client.Get;
    10 import org.apache.hadoop.hbase.client.HTable;
    11 import org.apache.hadoop.hbase.client.Put;
    12 import org.apache.hadoop.hbase.client.ResultScanner;
    13 import org.apache.hadoop.hbase.client.Scan;
    14 import org.apache.hadoop.hbase.util.Bytes;
    15 
    16 public class HBaseTest {
    17     public static void main(String[] args) throws Exception {
    18         HTable table = new HTable(getConfig(),TableName.valueOf("test_table"));//表名是test_table
    19 //        Put put = new Put(Bytes.toBytes("row_04"));//行键是row_04
    20 //        put.add(Bytes.toBytes("f"),Bytes.toBytes("name"),Bytes.toBytes("Andy1"));//列簇是f,列修饰符是name,值是Andy0
    21 //        put.add(Bytes.toBytes("f2"),Bytes.toBytes("name"),Bytes.toBytes("Andy3"));//列簇是f2,列修饰符是name,值是Andy3
    22 //        table.put(put);
    23 //        table.close();
    24 
    25 //        Get get = new Get(Bytes.toBytes("row_04"));
    26 //        get.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("age"));如现在这样,不指定,默认把所有的全拿出来
    27 //        org.apache.hadoop.hbase.client.Result rest = table.get(get);
    28 //        System.out.println(rest.toString());
    29 //        table.close();
    30 
    31 //        Delete delete = new Delete(Bytes.toBytes("row_2"));
    32 //        delete.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("email"));
    33 //        delete.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("name"));
    34 //        table.delete(delete);
    35 //        table.close();
    36 
    37 //        Delete delete = new Delete(Bytes.toBytes("row_04"));
    38 ////    delete.deleteColumn(Bytes.toBytes("f"), Bytes.toBytes("name"));//deleteColumn是删除某一个列簇里的最新时间戳版本。
    39 //        delete.deleteColumns(Bytes.toBytes("f"), Bytes.toBytes("name"));//delete.deleteColumns是删除某个列簇里的所有时间戳版本。
    40 //        table.delete(delete);
    41 //        table.close();
    42 
    43 
    44         Scan scan = new Scan();
    45         ResultScanner rst = table.getScanner(scan);
    46         System.out.println(rst.toString());
    47         for (org.apache.hadoop.hbase.client.Result next = rst.next();next !=null;next = rst.next() ){
    48             System.out.println(next.toString());
    49         }
    50         table.close();
    51 
    52     }    
    53 
    54     public static Configuration getConfig(){
    55         Configuration configuration = new Configuration(); 
    56 //        conf.set("hbase.rootdir","hdfs:HadoopMaster:9000/hbase");
    57         configuration.set("hbase.zookeeper.quorum", "HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181");
    58         return configuration;
    59     }
    60 }

     

    2016-12-10 17:29:53,501 INFO [org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper] - Process identifier=hconnection-0x7a45682c connecting to ZooKeeper ensemble=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181
    2016-12-10 17:29:53,520 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
    2016-12-10 17:29:53,520 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:host.name=WIN-BQOBV63OBNM
    2016-12-10 17:29:53,520 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.version=1.7.0_51
    2016-12-10 17:29:53,520 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.vendor=Oracle Corporation
    2016-12-10 17:29:53,520 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.home=C:Program FilesJavajdk1.7.0_51jre
    2016-12-10 17:29:53,521 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.class.path=D:CodeMyEclipseJavaCodeHbaseProjectin;D:SoftWarehbase-1.2.3libactivation-1.1.jar;D:SoftWarehbase-1.2.3libaopalliance-1.0.jar;D:SoftWarehbase-1.2.3libapacheds-i18n-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapacheds-kerberos-codec-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapi-asn1-api-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libapi-util-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libasm-3.1.jar;D:SoftWarehbase-1.2.3libavro-1.7.4.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-1.7.0.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-core-1.8.0.jar;D:SoftWarehbase-1.2.3libcommons-cli-1.2.jar;D:SoftWarehbase-1.2.3libcommons-codec-1.9.jar;D:SoftWarehbase-1.2.3libcommons-collections-3.2.2.jar;D:SoftWarehbase-1.2.3libcommons-compress-1.4.1.jar;D:SoftWarehbase-1.2.3libcommons-configuration-1.6.jar;D:SoftWarehbase-1.2.3libcommons-daemon-1.0.13.jar;D:SoftWarehbase-1.2.3libcommons-digester-1.8.jar;D:SoftWarehbase-1.2.3libcommons-el-1.0.jar;D:SoftWarehbase-1.2.3libcommons-httpclient-3.1.jar;D:SoftWarehbase-1.2.3libcommons-io-2.4.jar;D:SoftWarehbase-1.2.3libcommons-lang-2.6.jar;D:SoftWarehbase-1.2.3libcommons-logging-1.2.jar;D:SoftWarehbase-1.2.3libcommons-math-2.2.jar;D:SoftWarehbase-1.2.3libcommons-math3-3.1.1.jar;D:SoftWarehbase-1.2.3libcommons-net-3.1.jar;D:SoftWarehbase-1.2.3libdisruptor-3.3.0.jar;D:SoftWarehbase-1.2.3libfindbugs-annotations-1.3.9-1.jar;D:SoftWarehbase-1.2.3libguava-12.0.1.jar;D:SoftWarehbase-1.2.3libguice-3.0.jar;D:SoftWarehbase-1.2.3libguice-servlet-3.0.jar;D:SoftWarehbase-1.2.3libhadoop-annotations-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-auth-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-hdfs-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-app-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-core-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-jobclient-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-shuffle-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-api-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-server-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-client-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-examples-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-external-blockcache-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop2-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-prefix-tree-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-procedure-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-protocol-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-resource-bundle-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-rest-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-shell-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-thrift-1.2.3.jar;D:SoftWarehbase-1.2.3libhtrace-core-3.1.0-incubating.jar;D:SoftWarehbase-1.2.3libhttpclient-4.2.5.jar;D:SoftWarehbase-1.2.3libhttpcore-4.4.1.jar;D:SoftWarehbase-1.2.3libjackson-core-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-jaxrs-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-mapper-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-xc-1.9.13.jar;D:SoftWarehbase-1.2.3libjamon-runtime-2.4.1.jar;D:SoftWarehbase-1.2.3libjasper-compiler-5.5.23.jar;D:SoftWarehbase-1.2.3libjasper-runtime-5.5.23.jar;D:SoftWarehbase-1.2.3libjavax.inject-1.jar;D:SoftWarehbase-1.2.3libjava-xmlbuilder-0.4.jar;D:SoftWarehbase-1.2.3libjaxb-api-2.2.2.jar;D:SoftWarehbase-1.2.3libjaxb-impl-2.2.3-1.jar;D:SoftWarehbase-1.2.3libjcodings-1.0.8.jar;D:SoftWarehbase-1.2.3libjersey-client-1.9.jar;D:SoftWarehbase-1.2.3libjersey-core-1.9.jar;D:SoftWarehbase-1.2.3libjersey-guice-1.9.jar;D:SoftWarehbase-1.2.3libjersey-json-1.9.jar;D:SoftWarehbase-1.2.3libjersey-server-1.9.jar;D:SoftWarehbase-1.2.3libjets3t-0.9.0.jar;D:SoftWarehbase-1.2.3libjettison-1.3.3.jar;D:SoftWarehbase-1.2.3libjetty-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-sslengine-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-util-6.1.26.jar;D:SoftWarehbase-1.2.3libjoni-2.1.2.jar;D:SoftWarehbase-1.2.3libjruby-complete-1.6.8.jar;D:SoftWarehbase-1.2.3libjsch-0.1.42.jar;D:SoftWarehbase-1.2.3libjsp-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjsp-api-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjunit-4.12.jar;D:SoftWarehbase-1.2.3libleveldbjni-all-1.8.jar;D:SoftWarehbase-1.2.3liblibthrift-0.9.3.jar;D:SoftWarehbase-1.2.3liblog4j-1.2.17.jar;D:SoftWarehbase-1.2.3libmetrics-core-2.2.0.jar;D:SoftWarehbase-1.2.3lib etty-all-4.0.23.Final.jar;D:SoftWarehbase-1.2.3libparanamer-2.3.jar;D:SoftWarehbase-1.2.3libprotobuf-java-2.5.0.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5-6.1.14.jar;D:SoftWarehbase-1.2.3libslf4j-api-1.7.7.jar;D:SoftWarehbase-1.2.3libslf4j-log4j12-1.7.5.jar;D:SoftWarehbase-1.2.3libsnappy-java-1.0.4.1.jar;D:SoftWarehbase-1.2.3libspymemcached-2.11.6.jar;D:SoftWarehbase-1.2.3libxmlenc-0.52.jar;D:SoftWarehbase-1.2.3libxz-1.0.jar;D:SoftWarehbase-1.2.3libzookeeper-3.4.6.jar
    2016-12-10 17:29:53,522 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.library.path=C:Program FilesJavajdk1.7.0_51in;C:WindowsSunJavain;C:Windowssystem32;C:Windows;C:ProgramDataOracleJavajavapath;C:Python27;C:Python27Scripts;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;D:SoftWareMATLAB R2013a untimewin64;D:SoftWareMATLAB R2013ain;C:Program Files (x86)IDM Computer SolutionsUltraCompare;C:Program FilesJavajdk1.7.0_51in;C:Program FilesJavajdk1.7.0_51jrein;D:SoftWareapache-ant-1.9.0in;HADOOP_HOMEin;D:SoftWareapache-maven-3.3.9in;D:SoftWareScalain;D:SoftWareScalajrein;%MYSQL_HOMEin;D:SoftWareMySQL ServerMySQL Server 5.0in;D:SoftWareapache-tomcat-7.0.69in;%C:WindowsSystem32;%C:WindowsSysWOW64;D:SoftWareSSH Secure Shell;.
    2016-12-10 17:29:53,522 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.io.tmpdir=C:UsersADMINI~1AppDataLocalTemp
    2016-12-10 17:29:53,522 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.compiler=<NA>
    2016-12-10 17:29:53,522 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.name=Windows 7
    2016-12-10 17:29:53,522 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.arch=amd64
    2016-12-10 17:29:53,523 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.version=6.1
    2016-12-10 17:29:53,523 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.name=Administrator
    2016-12-10 17:29:53,523 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.home=C:UsersAdministrator
    2016-12-10 17:29:53,523 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.dir=D:CodeMyEclipseJavaCodeHbaseProject
    2016-12-10 17:29:53,525 INFO [org.apache.zookeeper.ZooKeeper] - Initiating client connection, connectString=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181 sessionTimeout=180000 watcher=hconnection-0x7a45682c0x0, quorum=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181, baseZNode=/hbase
    2016-12-10 17:29:53,588 INFO [org.apache.zookeeper.ClientCnxn] - Opening socket connection to server HadoopSlave1/192.168.80.11:2181. Will not attempt to authenticate using SASL (unknown error)
    2016-12-10 17:29:53,594 INFO [org.apache.zookeeper.ClientCnxn] - Socket connection established to HadoopSlave1/192.168.80.11:2181, initiating session
    2016-12-10 17:29:53,612 INFO [org.apache.zookeeper.ClientCnxn] - Session establishment complete on server HadoopSlave1/192.168.80.11:2181, sessionid = 0x2587338ecb40026, negotiated timeout = 40000
    org.apache.hadoop.hbase.client.ClientScanner@ff35374
    keyvalues={row_01/f:col/1478102698687/Put/vlen=5/seqid=0, row_01/f:name/1478104345828/Put/vlen=4/seqid=0}
    keyvalues={row_02/f:name/1478104477628/Put/vlen=5/seqid=0}
    keyvalues={row_03/f:name/1478123664884/Put/vlen=5/seqid=0}
    2016-12-10 17:29:54,863 INFO [org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation] - Closing zookeeper sessionid=0x2587338ecb40026
    2016-12-10 17:29:54,868 INFO [org.apache.zookeeper.ZooKeeper] - Session: 0x2587338ecb40026 closed
    2016-12-10 17:29:54,868 INFO [org.apache.zookeeper.ClientCnxn] - EventThread shut down

     1 package zhouls.bigdata.HbaseProject.Test1;
     2 
     3 import javax.xml.transform.Result;
     4 
     5 import org.apache.hadoop.conf.Configuration;
     6 import org.apache.hadoop.hbase.HBaseConfiguration;
     7 import org.apache.hadoop.hbase.TableName;
     8 import org.apache.hadoop.hbase.client.Delete;
     9 import org.apache.hadoop.hbase.client.Get;
    10 import org.apache.hadoop.hbase.client.HTable;
    11 import org.apache.hadoop.hbase.client.Put;
    12 import org.apache.hadoop.hbase.client.ResultScanner;
    13 import org.apache.hadoop.hbase.client.Scan;
    14 import org.apache.hadoop.hbase.util.Bytes;
    15 
    16 public class HBaseTest {
    17     public static void main(String[] args) throws Exception {
    18         HTable table = new HTable(getConfig(),TableName.valueOf("test_table2"));//表名是test_table2
    19 //        Put put = new Put(Bytes.toBytes("row_04"));//行键是row_04
    20 //        put.add(Bytes.toBytes("f"),Bytes.toBytes("name"),Bytes.toBytes("Andy1"));//列簇是f,列修饰符是name,值是Andy0
    21 //        put.add(Bytes.toBytes("f2"),Bytes.toBytes("name"),Bytes.toBytes("Andy3"));//列簇是f2,列修饰符是name,值是Andy3
    22 //        table.put(put);
    23 //        table.close();
    24 
    25 //        Get get = new Get(Bytes.toBytes("row_04"));
    26 //        get.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("age"));如现在这样,不指定,默认把所有的全拿出来
    27 //        org.apache.hadoop.hbase.client.Result rest = table.get(get);
    28 //        System.out.println(rest.toString());
    29 //        table.close();
    30 
    31 //        Delete delete = new Delete(Bytes.toBytes("row_2"));
    32 //        delete.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("email"));
    33 //        delete.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("name"));
    34 //        table.delete(delete);
    35 //        table.close();
    36 
    37 //        Delete delete = new Delete(Bytes.toBytes("row_04"));
    38 ////    delete.deleteColumn(Bytes.toBytes("f"), Bytes.toBytes("name"));//deleteColumn是删除某一个列簇里的最新时间戳版本。
    39 //        delete.deleteColumns(Bytes.toBytes("f"), Bytes.toBytes("name"));//delete.deleteColumns是删除某个列簇里的所有时间戳版本。
    40 //        table.delete(delete);
    41 //        table.close();
    42 
    43 
    44         Scan scan = new Scan();
    45         ResultScanner rst = table.getScanner(scan);
    46         System.out.println(rst.toString());
    47         for (org.apache.hadoop.hbase.client.Result next = rst.next();next !=null;next = rst.next() ){
    48             System.out.println(next.toString());
    49         }
    50         table.close();
    51 }
    52 
    53     public static Configuration getConfig(){
    54         Configuration configuration = new Configuration(); 
    55 //        conf.set("hbase.rootdir","hdfs:HadoopMaster:9000/hbase");
    56         configuration.set("hbase.zookeeper.quorum", "HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181");
    57         return configuration;
    58     }
    59 }

    2016-12-10 17:32:25,591 INFO [org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper] - Process identifier=hconnection-0x39ce5ac9 connecting to ZooKeeper ensemble=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181
    2016-12-10 17:32:25,612 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
    2016-12-10 17:32:25,613 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:host.name=WIN-BQOBV63OBNM
    2016-12-10 17:32:25,613 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.version=1.7.0_51
    2016-12-10 17:32:25,613 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.vendor=Oracle Corporation
    2016-12-10 17:32:25,613 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.home=C:Program FilesJavajdk1.7.0_51jre
    2016-12-10 17:32:25,613 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.class.path=D:CodeMyEclipseJavaCodeHbaseProjectin;D:SoftWarehbase-1.2.3libactivation-1.1.jar;D:SoftWarehbase-1.2.3libaopalliance-1.0.jar;D:SoftWarehbase-1.2.3libapacheds-i18n-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapacheds-kerberos-codec-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapi-asn1-api-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libapi-util-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libasm-3.1.jar;D:SoftWarehbase-1.2.3libavro-1.7.4.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-1.7.0.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-core-1.8.0.jar;D:SoftWarehbase-1.2.3libcommons-cli-1.2.jar;D:SoftWarehbase-1.2.3libcommons-codec-1.9.jar;D:SoftWarehbase-1.2.3libcommons-collections-3.2.2.jar;D:SoftWarehbase-1.2.3libcommons-compress-1.4.1.jar;D:SoftWarehbase-1.2.3libcommons-configuration-1.6.jar;D:SoftWarehbase-1.2.3libcommons-daemon-1.0.13.jar;D:SoftWarehbase-1.2.3libcommons-digester-1.8.jar;D:SoftWarehbase-1.2.3libcommons-el-1.0.jar;D:SoftWarehbase-1.2.3libcommons-httpclient-3.1.jar;D:SoftWarehbase-1.2.3libcommons-io-2.4.jar;D:SoftWarehbase-1.2.3libcommons-lang-2.6.jar;D:SoftWarehbase-1.2.3libcommons-logging-1.2.jar;D:SoftWarehbase-1.2.3libcommons-math-2.2.jar;D:SoftWarehbase-1.2.3libcommons-math3-3.1.1.jar;D:SoftWarehbase-1.2.3libcommons-net-3.1.jar;D:SoftWarehbase-1.2.3libdisruptor-3.3.0.jar;D:SoftWarehbase-1.2.3libfindbugs-annotations-1.3.9-1.jar;D:SoftWarehbase-1.2.3libguava-12.0.1.jar;D:SoftWarehbase-1.2.3libguice-3.0.jar;D:SoftWarehbase-1.2.3libguice-servlet-3.0.jar;D:SoftWarehbase-1.2.3libhadoop-annotations-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-auth-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-hdfs-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-app-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-core-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-jobclient-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-shuffle-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-api-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-server-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-client-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-examples-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-external-blockcache-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop2-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-prefix-tree-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-procedure-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-protocol-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-resource-bundle-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-rest-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-shell-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-thrift-1.2.3.jar;D:SoftWarehbase-1.2.3libhtrace-core-3.1.0-incubating.jar;D:SoftWarehbase-1.2.3libhttpclient-4.2.5.jar;D:SoftWarehbase-1.2.3libhttpcore-4.4.1.jar;D:SoftWarehbase-1.2.3libjackson-core-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-jaxrs-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-mapper-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-xc-1.9.13.jar;D:SoftWarehbase-1.2.3libjamon-runtime-2.4.1.jar;D:SoftWarehbase-1.2.3libjasper-compiler-5.5.23.jar;D:SoftWarehbase-1.2.3libjasper-runtime-5.5.23.jar;D:SoftWarehbase-1.2.3libjavax.inject-1.jar;D:SoftWarehbase-1.2.3libjava-xmlbuilder-0.4.jar;D:SoftWarehbase-1.2.3libjaxb-api-2.2.2.jar;D:SoftWarehbase-1.2.3libjaxb-impl-2.2.3-1.jar;D:SoftWarehbase-1.2.3libjcodings-1.0.8.jar;D:SoftWarehbase-1.2.3libjersey-client-1.9.jar;D:SoftWarehbase-1.2.3libjersey-core-1.9.jar;D:SoftWarehbase-1.2.3libjersey-guice-1.9.jar;D:SoftWarehbase-1.2.3libjersey-json-1.9.jar;D:SoftWarehbase-1.2.3libjersey-server-1.9.jar;D:SoftWarehbase-1.2.3libjets3t-0.9.0.jar;D:SoftWarehbase-1.2.3libjettison-1.3.3.jar;D:SoftWarehbase-1.2.3libjetty-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-sslengine-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-util-6.1.26.jar;D:SoftWarehbase-1.2.3libjoni-2.1.2.jar;D:SoftWarehbase-1.2.3libjruby-complete-1.6.8.jar;D:SoftWarehbase-1.2.3libjsch-0.1.42.jar;D:SoftWarehbase-1.2.3libjsp-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjsp-api-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjunit-4.12.jar;D:SoftWarehbase-1.2.3libleveldbjni-all-1.8.jar;D:SoftWarehbase-1.2.3liblibthrift-0.9.3.jar;D:SoftWarehbase-1.2.3liblog4j-1.2.17.jar;D:SoftWarehbase-1.2.3libmetrics-core-2.2.0.jar;D:SoftWarehbase-1.2.3lib etty-all-4.0.23.Final.jar;D:SoftWarehbase-1.2.3libparanamer-2.3.jar;D:SoftWarehbase-1.2.3libprotobuf-java-2.5.0.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5-6.1.14.jar;D:SoftWarehbase-1.2.3libslf4j-api-1.7.7.jar;D:SoftWarehbase-1.2.3libslf4j-log4j12-1.7.5.jar;D:SoftWarehbase-1.2.3libsnappy-java-1.0.4.1.jar;D:SoftWarehbase-1.2.3libspymemcached-2.11.6.jar;D:SoftWarehbase-1.2.3libxmlenc-0.52.jar;D:SoftWarehbase-1.2.3libxz-1.0.jar;D:SoftWarehbase-1.2.3libzookeeper-3.4.6.jar
    2016-12-10 17:32:25,615 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.library.path=C:Program FilesJavajdk1.7.0_51in;C:WindowsSunJavain;C:Windowssystem32;C:Windows;C:ProgramDataOracleJavajavapath;C:Python27;C:Python27Scripts;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;D:SoftWareMATLAB R2013a untimewin64;D:SoftWareMATLAB R2013ain;C:Program Files (x86)IDM Computer SolutionsUltraCompare;C:Program FilesJavajdk1.7.0_51in;C:Program FilesJavajdk1.7.0_51jrein;D:SoftWareapache-ant-1.9.0in;HADOOP_HOMEin;D:SoftWareapache-maven-3.3.9in;D:SoftWareScalain;D:SoftWareScalajrein;%MYSQL_HOMEin;D:SoftWareMySQL ServerMySQL Server 5.0in;D:SoftWareapache-tomcat-7.0.69in;%C:WindowsSystem32;%C:WindowsSysWOW64;D:SoftWareSSH Secure Shell;.
    2016-12-10 17:32:25,615 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.io.tmpdir=C:UsersADMINI~1AppDataLocalTemp
    2016-12-10 17:32:25,615 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.compiler=<NA>
    2016-12-10 17:32:25,616 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.name=Windows 7
    2016-12-10 17:32:25,616 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.arch=amd64
    2016-12-10 17:32:25,616 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.version=6.1
    2016-12-10 17:32:25,616 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.name=Administrator
    2016-12-10 17:32:25,616 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.home=C:UsersAdministrator
    2016-12-10 17:32:25,617 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.dir=D:CodeMyEclipseJavaCodeHbaseProject
    2016-12-10 17:32:25,619 INFO [org.apache.zookeeper.ZooKeeper] - Initiating client connection, connectString=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181 sessionTimeout=180000 watcher=hconnection-0x39ce5ac90x0, quorum=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181, baseZNode=/hbase
    2016-12-10 17:32:25,701 INFO [org.apache.zookeeper.ClientCnxn] - Opening socket connection to server HadoopMaster/192.168.80.10:2181. Will not attempt to authenticate using SASL (unknown error)
    2016-12-10 17:32:25,705 INFO [org.apache.zookeeper.ClientCnxn] - Socket connection established to HadoopMaster/192.168.80.10:2181, initiating session
    2016-12-10 17:32:25,762 INFO [org.apache.zookeeper.ClientCnxn] - Session establishment complete on server HadoopMaster/192.168.80.10:2181, sessionid = 0x15825dedcf4002e, negotiated timeout = 40000
    org.apache.hadoop.hbase.client.ClientScanner@529d8124
    keyvalues={row_1/f1:age/1478119757136/Put/vlen=2/seqid=0, row_1/f1:name/1478119459805/Put/vlen=4/seqid=0}
    2016-12-10 17:32:27,091 INFO [org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation] - Closing zookeeper sessionid=0x15825dedcf4002e
    2016-12-10 17:32:27,099 INFO [org.apache.zookeeper.ZooKeeper] - Session: 0x15825dedcf4002e closed
    2016-12-10 17:32:27,100 INFO [org.apache.zookeeper.ClientCnxn] - EventThread shut down

    1     Scan scan = new Scan();
    2     scan.setStartRow(Bytes.toBytes("3"));
    3     ResultScanner rst = table.getScanner(scan);
    4     System.out.println(rst.toString());
    5     for (org.apache.hadoop.hbase.client.Result next = rst.next();next !=null;next = rst.next() ){
    6         System.out.println(next.toString());
    7     }
    8     table.close();

    1     Scan scan = new Scan();
    2     scan.setStartRow(Bytes.toBytes("3"));//包含开始行键
    3     scan.setStopRow(Bytes.toBytes("5"));//不包含结束行键
    4     ResultScanner rst = table.getScanner(scan);
    5     System.out.println(rst.toString());
    6     for (org.apache.hadoop.hbase.client.Result next = rst.next();next !=null;next = rst.next() ){
    7         System.out.println(next.toString());
    8     }
    9     table.close();


    1     Scan scan = new Scan();
    2     scan.setStartRow(Bytes.toBytes("1"));//包含开始行键
    3     scan.setStopRow(Bytes.toBytes("5"));//不包含结束行键
    4     ResultScanner rst = table.getScanner(scan);
    5     System.out.println(rst.toString());
    6     for (org.apache.hadoop.hbase.client.Result next = rst.next();next !=null;next = rst.next() ){
    7         System.out.println(next.toString());
    8     }
    9     table.close();

     1     Scan scan = new Scan();
     2     scan.setStartRow(Bytes.toBytes("1"));//包含开始行键
     3     scan.setStopRow(Bytes.toBytes("5"));//不包含结束行键
     4     ResultScanner rst = table.getScanner(scan);
     5     System.out.println(rst.toString());
     6     for (org.apache.hadoop.hbase.client.Result next = rst.next();next !=null;next = rst.next() ){
     7         for(Cell cell:next.rawCells()){
     8             System.out.println(next.toString());
     9             System.out.println("family:" + Bytes.toString(CellUtil.cloneFamily(cell)));
    10             System.out.println("col:" + Bytes.toString(CellUtil.cloneQualifier(cell)));
    11             System.out.println("value" + Bytes.toString(CellUtil.cloneValue(cell)));
    12         }
    13     }
    14     table.close();

     

     1 package zhouls.bigdata.HbaseProject.Test1;
     2 
     3 import javax.xml.transform.Result;
     4 
     5 import org.apache.hadoop.conf.Configuration;
     6 import org.apache.hadoop.hbase.Cell;
     7 import org.apache.hadoop.hbase.CellUtil;
     8 import org.apache.hadoop.hbase.HBaseConfiguration;
     9 import org.apache.hadoop.hbase.TableName;
    10 import org.apache.hadoop.hbase.client.Delete;
    11 import org.apache.hadoop.hbase.client.Get;
    12 import org.apache.hadoop.hbase.client.HTable;
    13 import org.apache.hadoop.hbase.client.Put;
    14 import org.apache.hadoop.hbase.client.ResultScanner;
    15 import org.apache.hadoop.hbase.client.Scan;
    16 import org.apache.hadoop.hbase.util.Bytes;
    17 
    18 public class HBaseTest {
    19     public static void main(String[] args) throws Exception {
    20         HTable table = new HTable(getConfig(),TableName.valueOf("test_table"));//表名是test_table
    21 //        Put put = new Put(Bytes.toBytes("row_04"));//行键是row_04
    22 //        put.add(Bytes.toBytes("f"),Bytes.toBytes("name"),Bytes.toBytes("Andy1"));//列簇是f,列修饰符是name,值是Andy0
    23 //        put.add(Bytes.toBytes("f2"),Bytes.toBytes("name"),Bytes.toBytes("Andy3"));//列簇是f2,列修饰符是name,值是Andy3
    24 //        table.put(put);
    25 //        table.close();
    26 
    27 //        Get get = new Get(Bytes.toBytes("row_04"));
    28 //        get.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("age"));如现在这样,不指定,默认把所有的全拿出来
    29 //        org.apache.hadoop.hbase.client.Result rest = table.get(get);
    30 //        System.out.println(rest.toString());
    31 //        table.close();
    32 
    33 //        Delete delete = new Delete(Bytes.toBytes("row_2"));
    34 //        delete.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("email"));
    35 //        delete.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("name"));
    36 //        table.delete(delete);
    37 //        table.close();
    38 
    39 //        Delete delete = new Delete(Bytes.toBytes("row_04"));
    40 ////    delete.deleteColumn(Bytes.toBytes("f"), Bytes.toBytes("name"));//deleteColumn是删除某一个列簇里的最新时间戳版本。
    41 //        delete.deleteColumns(Bytes.toBytes("f"), Bytes.toBytes("name"));//delete.deleteColumns是删除某个列簇里的所有时间戳版本。
    42 //        table.delete(delete);
    43 //        table.close();
    44 
    45 
    46         Scan scan = new Scan();
    47         scan.setStartRow(Bytes.toBytes("row_01"));//包含开始行键
    48         scan.setStopRow(Bytes.toBytes("row_03"));//不包含结束行键
    49         ResultScanner rst = table.getScanner(scan);
    50         System.out.println(rst.toString());
    51         for (org.apache.hadoop.hbase.client.Result next = rst.next();next !=null;next = rst.next() ){
    52             for(Cell cell:next.rawCells()){
    53                 System.out.println(next.toString());
    54                 System.out.println("family:" + Bytes.toString(CellUtil.cloneFamily(cell)));
    55                 System.out.println("col:" + Bytes.toString(CellUtil.cloneQualifier(cell)));
    56                 System.out.println("value" + Bytes.toString(CellUtil.cloneValue(cell)));
    57             }
    58         }
    59         table.close();
    60     }
    61 
    62     public static Configuration getConfig(){
    63         Configuration configuration = new Configuration(); 
    64 //        conf.set("hbase.rootdir","hdfs:HadoopMaster:9000/hbase");
    65         configuration.set("hbase.zookeeper.quorum", "HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181");
    66         return configuration;
    67     }
    68 }

    2016-12-10 17:58:16,226 INFO [org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper] - Process identifier=hconnection-0x7efa391e connecting to ZooKeeper ensemble=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181
    2016-12-10 17:58:16,265 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
    2016-12-10 17:58:16,267 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:host.name=WIN-BQOBV63OBNM
    2016-12-10 17:58:16,267 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.version=1.7.0_51
    2016-12-10 17:58:16,267 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.vendor=Oracle Corporation
    2016-12-10 17:58:16,268 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.home=C:Program FilesJavajdk1.7.0_51jre
    2016-12-10 17:58:16,268 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.class.path=D:CodeMyEclipseJavaCodeHbaseProjectin;D:SoftWarehbase-1.2.3libactivation-1.1.jar;D:SoftWarehbase-1.2.3libaopalliance-1.0.jar;D:SoftWarehbase-1.2.3libapacheds-i18n-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapacheds-kerberos-codec-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapi-asn1-api-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libapi-util-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libasm-3.1.jar;D:SoftWarehbase-1.2.3libavro-1.7.4.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-1.7.0.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-core-1.8.0.jar;D:SoftWarehbase-1.2.3libcommons-cli-1.2.jar;D:SoftWarehbase-1.2.3libcommons-codec-1.9.jar;D:SoftWarehbase-1.2.3libcommons-collections-3.2.2.jar;D:SoftWarehbase-1.2.3libcommons-compress-1.4.1.jar;D:SoftWarehbase-1.2.3libcommons-configuration-1.6.jar;D:SoftWarehbase-1.2.3libcommons-daemon-1.0.13.jar;D:SoftWarehbase-1.2.3libcommons-digester-1.8.jar;D:SoftWarehbase-1.2.3libcommons-el-1.0.jar;D:SoftWarehbase-1.2.3libcommons-httpclient-3.1.jar;D:SoftWarehbase-1.2.3libcommons-io-2.4.jar;D:SoftWarehbase-1.2.3libcommons-lang-2.6.jar;D:SoftWarehbase-1.2.3libcommons-logging-1.2.jar;D:SoftWarehbase-1.2.3libcommons-math-2.2.jar;D:SoftWarehbase-1.2.3libcommons-math3-3.1.1.jar;D:SoftWarehbase-1.2.3libcommons-net-3.1.jar;D:SoftWarehbase-1.2.3libdisruptor-3.3.0.jar;D:SoftWarehbase-1.2.3libfindbugs-annotations-1.3.9-1.jar;D:SoftWarehbase-1.2.3libguava-12.0.1.jar;D:SoftWarehbase-1.2.3libguice-3.0.jar;D:SoftWarehbase-1.2.3libguice-servlet-3.0.jar;D:SoftWarehbase-1.2.3libhadoop-annotations-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-auth-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-hdfs-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-app-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-core-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-jobclient-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-shuffle-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-api-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-server-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-client-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-examples-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-external-blockcache-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop2-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-prefix-tree-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-procedure-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-protocol-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-resource-bundle-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-rest-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-shell-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-thrift-1.2.3.jar;D:SoftWarehbase-1.2.3libhtrace-core-3.1.0-incubating.jar;D:SoftWarehbase-1.2.3libhttpclient-4.2.5.jar;D:SoftWarehbase-1.2.3libhttpcore-4.4.1.jar;D:SoftWarehbase-1.2.3libjackson-core-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-jaxrs-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-mapper-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-xc-1.9.13.jar;D:SoftWarehbase-1.2.3libjamon-runtime-2.4.1.jar;D:SoftWarehbase-1.2.3libjasper-compiler-5.5.23.jar;D:SoftWarehbase-1.2.3libjasper-runtime-5.5.23.jar;D:SoftWarehbase-1.2.3libjavax.inject-1.jar;D:SoftWarehbase-1.2.3libjava-xmlbuilder-0.4.jar;D:SoftWarehbase-1.2.3libjaxb-api-2.2.2.jar;D:SoftWarehbase-1.2.3libjaxb-impl-2.2.3-1.jar;D:SoftWarehbase-1.2.3libjcodings-1.0.8.jar;D:SoftWarehbase-1.2.3libjersey-client-1.9.jar;D:SoftWarehbase-1.2.3libjersey-core-1.9.jar;D:SoftWarehbase-1.2.3libjersey-guice-1.9.jar;D:SoftWarehbase-1.2.3libjersey-json-1.9.jar;D:SoftWarehbase-1.2.3libjersey-server-1.9.jar;D:SoftWarehbase-1.2.3libjets3t-0.9.0.jar;D:SoftWarehbase-1.2.3libjettison-1.3.3.jar;D:SoftWarehbase-1.2.3libjetty-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-sslengine-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-util-6.1.26.jar;D:SoftWarehbase-1.2.3libjoni-2.1.2.jar;D:SoftWarehbase-1.2.3libjruby-complete-1.6.8.jar;D:SoftWarehbase-1.2.3libjsch-0.1.42.jar;D:SoftWarehbase-1.2.3libjsp-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjsp-api-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjunit-4.12.jar;D:SoftWarehbase-1.2.3libleveldbjni-all-1.8.jar;D:SoftWarehbase-1.2.3liblibthrift-0.9.3.jar;D:SoftWarehbase-1.2.3liblog4j-1.2.17.jar;D:SoftWarehbase-1.2.3libmetrics-core-2.2.0.jar;D:SoftWarehbase-1.2.3lib etty-all-4.0.23.Final.jar;D:SoftWarehbase-1.2.3libparanamer-2.3.jar;D:SoftWarehbase-1.2.3libprotobuf-java-2.5.0.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5-6.1.14.jar;D:SoftWarehbase-1.2.3libslf4j-api-1.7.7.jar;D:SoftWarehbase-1.2.3libslf4j-log4j12-1.7.5.jar;D:SoftWarehbase-1.2.3libsnappy-java-1.0.4.1.jar;D:SoftWarehbase-1.2.3libspymemcached-2.11.6.jar;D:SoftWarehbase-1.2.3libxmlenc-0.52.jar;D:SoftWarehbase-1.2.3libxz-1.0.jar;D:SoftWarehbase-1.2.3libzookeeper-3.4.6.jar
    2016-12-10 17:58:16,270 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.library.path=C:Program FilesJavajdk1.7.0_51in;C:WindowsSunJavain;C:Windowssystem32;C:Windows;C:ProgramDataOracleJavajavapath;C:Python27;C:Python27Scripts;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;D:SoftWareMATLAB R2013a untimewin64;D:SoftWareMATLAB R2013ain;C:Program Files (x86)IDM Computer SolutionsUltraCompare;C:Program FilesJavajdk1.7.0_51in;C:Program FilesJavajdk1.7.0_51jrein;D:SoftWareapache-ant-1.9.0in;HADOOP_HOMEin;D:SoftWareapache-maven-3.3.9in;D:SoftWareScalain;D:SoftWareScalajrein;%MYSQL_HOMEin;D:SoftWareMySQL ServerMySQL Server 5.0in;D:SoftWareapache-tomcat-7.0.69in;%C:WindowsSystem32;%C:WindowsSysWOW64;D:SoftWareSSH Secure Shell;.
    2016-12-10 17:58:16,271 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.io.tmpdir=C:UsersADMINI~1AppDataLocalTemp
    2016-12-10 17:58:16,271 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.compiler=<NA>
    2016-12-10 17:58:16,271 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.name=Windows 7
    2016-12-10 17:58:16,272 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.arch=amd64
    2016-12-10 17:58:16,272 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.version=6.1
    2016-12-10 17:58:16,272 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.name=Administrator
    2016-12-10 17:58:16,273 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.home=C:UsersAdministrator
    2016-12-10 17:58:16,273 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.dir=D:CodeMyEclipseJavaCodeHbaseProject
    2016-12-10 17:58:16,278 INFO [org.apache.zookeeper.ZooKeeper] - Initiating client connection, connectString=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181 sessionTimeout=180000 watcher=hconnection-0x7efa391e0x0, quorum=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181, baseZNode=/hbase
    2016-12-10 17:58:16,408 INFO [org.apache.zookeeper.ClientCnxn] - Opening socket connection to server HadoopSlave1/192.168.80.11:2181. Will not attempt to authenticate using SASL (unknown error)
    2016-12-10 17:58:16,438 INFO [org.apache.zookeeper.ClientCnxn] - Socket connection established to HadoopSlave1/192.168.80.11:2181, initiating session
    2016-12-10 17:58:16,474 INFO [org.apache.zookeeper.ClientCnxn] - Session establishment complete on server HadoopSlave1/192.168.80.11:2181, sessionid = 0x2587338ecb40027, negotiated timeout = 40000
    org.apache.hadoop.hbase.client.ClientScanner@634be93a
    keyvalues={row_01/f:col/1478102698687/Put/vlen=5/seqid=0, row_01/f:name/1478104345828/Put/vlen=4/seqid=0}
    family:f
    col:col
    valuemaizi
    keyvalues={row_01/f:col/1478102698687/Put/vlen=5/seqid=0, row_01/f:name/1478104345828/Put/vlen=4/seqid=0}
    family:f
    col:name
    valueAndy
    keyvalues={row_02/f:name/1478104477628/Put/vlen=5/seqid=0}
    family:f
    col:name
    valueAndy2
    2016-12-10 17:58:17,994 INFO [org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation] - Closing zookeeper sessionid=0x2587338ecb40027
    2016-12-10 17:58:18,001 INFO [org.apache.zookeeper.ZooKeeper] - Session: 0x2587338ecb40027 closed
    2016-12-10 17:58:18,001 INFO [org.apache.zookeeper.ClientCnxn] - EventThread shut down

    代码解释一

     1     Scan scan = new Scan();
     2     scan.setStartRow(Bytes.toBytes("row_01"));//包含开始行键
     3     scan.setStopRow(Bytes.toBytes("row_03"));//不包含结束行键
     4     ResultScanner rst = table.getScanner(scan);
     5     System.out.println(rst.toString());
     6     for (org.apache.hadoop.hbase.client.Result next = rst.next();next !=null;next = rst.next() ){
     7         for(Cell cell:next.rawCells()){
     8             System.out.println(next.toString());
     9             System.out.println("family:" + Bytes.toString(CellUtil.cloneFamily(cell)));
    10             System.out.println("col:" + Bytes.toString(CellUtil.cloneQualifier(cell)));
    11             System.out.println("value" + Bytes.toString(CellUtil.cloneValue(cell)));
    12         }
    13     }
    14     table.close();

    代码解释二

     

     1     Scan scan = new Scan();
     2     scan.setStartRow(Bytes.toBytes("row_01"));//包含开始行键
     3     scan.setStopRow(Bytes.toBytes("row_03"));//不包含结束行键
     4     ResultScanner rst = table.getScanner(scan);
     5     System.out.println(rst.toString());
     6     for (org.apache.hadoop.hbase.client.Result next = rst.next();next !=null;next = rst.next() ){
     7         for(Cell cell:next.rawCells()){
     8             System.out.println(next.toString());
     9             System.out.println("family:" + Bytes.toString(CellUtil.cloneFamily(cell)));
    10             System.out.println("col:" + Bytes.toString(CellUtil.cloneQualifier(cell)));
    11             System.out.println("value" + Bytes.toString(CellUtil.cloneValue(cell)));
    12         }
    13     }
    14     table.close();

     

     1 package zhouls.bigdata.HbaseProject.Test1;
     2 
     3 import javax.xml.transform.Result;
     4 
     5 import org.apache.hadoop.conf.Configuration;
     6 import org.apache.hadoop.hbase.Cell;
     7 import org.apache.hadoop.hbase.CellUtil;
     8 import org.apache.hadoop.hbase.HBaseConfiguration;
     9 import org.apache.hadoop.hbase.TableName;
    10 import org.apache.hadoop.hbase.client.Delete;
    11 import org.apache.hadoop.hbase.client.Get;
    12 import org.apache.hadoop.hbase.client.HTable;
    13 import org.apache.hadoop.hbase.client.Put;
    14 import org.apache.hadoop.hbase.client.ResultScanner;
    15 import org.apache.hadoop.hbase.client.Scan;
    16 import org.apache.hadoop.hbase.util.Bytes;
    17 
    18 public class HBaseTest {
    19     public static void main(String[] args) throws Exception {
    20         HTable table = new HTable(getConfig(),TableName.valueOf("test_table"));//表名是test_table
    21 //        Put put = new Put(Bytes.toBytes("row_04"));//行键是row_04
    22 //        put.add(Bytes.toBytes("f"),Bytes.toBytes("name"),Bytes.toBytes("Andy1"));//列簇是f,列修饰符是name,值是Andy0
    23 //        put.add(Bytes.toBytes("f2"),Bytes.toBytes("name"),Bytes.toBytes("Andy3"));//列簇是f2,列修饰符是name,值是Andy3
    24 //        table.put(put);
    25 //        table.close();
    26 
    27 //        Get get = new Get(Bytes.toBytes("row_04"));
    28 //        get.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("age"));如现在这样,不指定,默认把所有的全拿出来
    29 //        org.apache.hadoop.hbase.client.Result rest = table.get(get);
    30 //        System.out.println(rest.toString());
    31 //        table.close();
    32 
    33 //        Delete delete = new Delete(Bytes.toBytes("row_2"));
    34 //        delete.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("email"));
    35 //        delete.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("name"));
    36 //        table.delete(delete);
    37 //        table.close();
    38 
    39 //        Delete delete = new Delete(Bytes.toBytes("row_04"));
    40 ////    delete.deleteColumn(Bytes.toBytes("f"), Bytes.toBytes("name"));//deleteColumn是删除某一个列簇里的最新时间戳版本。
    41 //        delete.deleteColumns(Bytes.toBytes("f"), Bytes.toBytes("name"));//delete.deleteColumns是删除某个列簇里的所有时间戳版本。
    42 //        table.delete(delete);
    43 //        table.close();
    44 
    45 
    46         Scan scan = new Scan();
    47         scan.setStartRow(Bytes.toBytes("row_01"));//包含开始行键
    48         scan.setStopRow(Bytes.toBytes("row_03"));//不包含结束行键
    49         scan.addColumn(Bytes.toBytes("f"), Bytes.toBytes("name"));
    50         ResultScanner rst = table.getScanner(scan);//整个循环
    51         System.out.println(rst.toString());
    52         for (org.apache.hadoop.hbase.client.Result next = rst.next();next !=null;next = rst.next() ){
    53             for(Cell cell:next.rawCells()){//某个row key下的循坏
    54                 System.out.println(next.toString());
    55                 System.out.println("family:" + Bytes.toString(CellUtil.cloneFamily(cell)));
    56                 System.out.println("col:" + Bytes.toString(CellUtil.cloneQualifier(cell)));
    57                 System.out.println("value" + Bytes.toString(CellUtil.cloneValue(cell)));
    58             }
    59         }
    60         table.close();
    61     }
    62 
    63     public static Configuration getConfig(){
    64         Configuration configuration = new Configuration(); 
    65 //        conf.set("hbase.rootdir","hdfs:HadoopMaster:9000/hbase");
    66         configuration.set("hbase.zookeeper.quorum", "HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181");
    67         return configuration;
    68     }
    69 }

     

    2016-12-10 18:09:00,581 INFO [org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper] - Process identifier=hconnection-0xbe4535e connecting to ZooKeeper ensemble=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181
    2016-12-10 18:09:00,600 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
    2016-12-10 18:09:00,601 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:host.name=WIN-BQOBV63OBNM
    2016-12-10 18:09:00,601 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.version=1.7.0_51
    2016-12-10 18:09:00,601 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.vendor=Oracle Corporation
    2016-12-10 18:09:00,601 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.home=C:Program FilesJavajdk1.7.0_51jre
    2016-12-10 18:09:00,601 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.class.path=D:CodeMyEclipseJavaCodeHbaseProjectin;D:SoftWarehbase-1.2.3libactivation-1.1.jar;D:SoftWarehbase-1.2.3libaopalliance-1.0.jar;D:SoftWarehbase-1.2.3libapacheds-i18n-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapacheds-kerberos-codec-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapi-asn1-api-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libapi-util-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libasm-3.1.jar;D:SoftWarehbase-1.2.3libavro-1.7.4.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-1.7.0.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-core-1.8.0.jar;D:SoftWarehbase-1.2.3libcommons-cli-1.2.jar;D:SoftWarehbase-1.2.3libcommons-codec-1.9.jar;D:SoftWarehbase-1.2.3libcommons-collections-3.2.2.jar;D:SoftWarehbase-1.2.3libcommons-compress-1.4.1.jar;D:SoftWarehbase-1.2.3libcommons-configuration-1.6.jar;D:SoftWarehbase-1.2.3libcommons-daemon-1.0.13.jar;D:SoftWarehbase-1.2.3libcommons-digester-1.8.jar;D:SoftWarehbase-1.2.3libcommons-el-1.0.jar;D:SoftWarehbase-1.2.3libcommons-httpclient-3.1.jar;D:SoftWarehbase-1.2.3libcommons-io-2.4.jar;D:SoftWarehbase-1.2.3libcommons-lang-2.6.jar;D:SoftWarehbase-1.2.3libcommons-logging-1.2.jar;D:SoftWarehbase-1.2.3libcommons-math-2.2.jar;D:SoftWarehbase-1.2.3libcommons-math3-3.1.1.jar;D:SoftWarehbase-1.2.3libcommons-net-3.1.jar;D:SoftWarehbase-1.2.3libdisruptor-3.3.0.jar;D:SoftWarehbase-1.2.3libfindbugs-annotations-1.3.9-1.jar;D:SoftWarehbase-1.2.3libguava-12.0.1.jar;D:SoftWarehbase-1.2.3libguice-3.0.jar;D:SoftWarehbase-1.2.3libguice-servlet-3.0.jar;D:SoftWarehbase-1.2.3libhadoop-annotations-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-auth-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-hdfs-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-app-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-core-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-jobclient-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-shuffle-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-api-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-server-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-client-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-examples-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-external-blockcache-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop2-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-prefix-tree-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-procedure-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-protocol-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-resource-bundle-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-rest-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-shell-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-thrift-1.2.3.jar;D:SoftWarehbase-1.2.3libhtrace-core-3.1.0-incubating.jar;D:SoftWarehbase-1.2.3libhttpclient-4.2.5.jar;D:SoftWarehbase-1.2.3libhttpcore-4.4.1.jar;D:SoftWarehbase-1.2.3libjackson-core-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-jaxrs-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-mapper-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-xc-1.9.13.jar;D:SoftWarehbase-1.2.3libjamon-runtime-2.4.1.jar;D:SoftWarehbase-1.2.3libjasper-compiler-5.5.23.jar;D:SoftWarehbase-1.2.3libjasper-runtime-5.5.23.jar;D:SoftWarehbase-1.2.3libjavax.inject-1.jar;D:SoftWarehbase-1.2.3libjava-xmlbuilder-0.4.jar;D:SoftWarehbase-1.2.3libjaxb-api-2.2.2.jar;D:SoftWarehbase-1.2.3libjaxb-impl-2.2.3-1.jar;D:SoftWarehbase-1.2.3libjcodings-1.0.8.jar;D:SoftWarehbase-1.2.3libjersey-client-1.9.jar;D:SoftWarehbase-1.2.3libjersey-core-1.9.jar;D:SoftWarehbase-1.2.3libjersey-guice-1.9.jar;D:SoftWarehbase-1.2.3libjersey-json-1.9.jar;D:SoftWarehbase-1.2.3libjersey-server-1.9.jar;D:SoftWarehbase-1.2.3libjets3t-0.9.0.jar;D:SoftWarehbase-1.2.3libjettison-1.3.3.jar;D:SoftWarehbase-1.2.3libjetty-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-sslengine-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-util-6.1.26.jar;D:SoftWarehbase-1.2.3libjoni-2.1.2.jar;D:SoftWarehbase-1.2.3libjruby-complete-1.6.8.jar;D:SoftWarehbase-1.2.3libjsch-0.1.42.jar;D:SoftWarehbase-1.2.3libjsp-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjsp-api-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjunit-4.12.jar;D:SoftWarehbase-1.2.3libleveldbjni-all-1.8.jar;D:SoftWarehbase-1.2.3liblibthrift-0.9.3.jar;D:SoftWarehbase-1.2.3liblog4j-1.2.17.jar;D:SoftWarehbase-1.2.3libmetrics-core-2.2.0.jar;D:SoftWarehbase-1.2.3lib etty-all-4.0.23.Final.jar;D:SoftWarehbase-1.2.3libparanamer-2.3.jar;D:SoftWarehbase-1.2.3libprotobuf-java-2.5.0.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5-6.1.14.jar;D:SoftWarehbase-1.2.3libslf4j-api-1.7.7.jar;D:SoftWarehbase-1.2.3libslf4j-log4j12-1.7.5.jar;D:SoftWarehbase-1.2.3libsnappy-java-1.0.4.1.jar;D:SoftWarehbase-1.2.3libspymemcached-2.11.6.jar;D:SoftWarehbase-1.2.3libxmlenc-0.52.jar;D:SoftWarehbase-1.2.3libxz-1.0.jar;D:SoftWarehbase-1.2.3libzookeeper-3.4.6.jar
    2016-12-10 18:09:00,603 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.library.path=C:Program FilesJavajdk1.7.0_51in;C:WindowsSunJavain;C:Windowssystem32;C:Windows;C:ProgramDataOracleJavajavapath;C:Python27;C:Python27Scripts;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;D:SoftWareMATLAB R2013a untimewin64;D:SoftWareMATLAB R2013ain;C:Program Files (x86)IDM Computer SolutionsUltraCompare;C:Program FilesJavajdk1.7.0_51in;C:Program FilesJavajdk1.7.0_51jrein;D:SoftWareapache-ant-1.9.0in;HADOOP_HOMEin;D:SoftWareapache-maven-3.3.9in;D:SoftWareScalain;D:SoftWareScalajrein;%MYSQL_HOMEin;D:SoftWareMySQL ServerMySQL Server 5.0in;D:SoftWareapache-tomcat-7.0.69in;%C:WindowsSystem32;%C:WindowsSysWOW64;D:SoftWareSSH Secure Shell;.
    2016-12-10 18:09:00,603 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.io.tmpdir=C:UsersADMINI~1AppDataLocalTemp
    2016-12-10 18:09:00,604 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.compiler=<NA>
    2016-12-10 18:09:00,604 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.name=Windows 7
    2016-12-10 18:09:00,604 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.arch=amd64
    2016-12-10 18:09:00,604 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.version=6.1
    2016-12-10 18:09:00,605 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.name=Administrator
    2016-12-10 18:09:00,605 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.home=C:UsersAdministrator
    2016-12-10 18:09:00,605 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.dir=D:CodeMyEclipseJavaCodeHbaseProject
    2016-12-10 18:09:00,609 INFO [org.apache.zookeeper.ZooKeeper] - Initiating client connection, connectString=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181 sessionTimeout=180000 watcher=hconnection-0xbe4535e0x0, quorum=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181, baseZNode=/hbase
    2016-12-10 18:09:00,717 INFO [org.apache.zookeeper.ClientCnxn] - Opening socket connection to server HadoopMaster/192.168.80.10:2181. Will not attempt to authenticate using SASL (unknown error)
    2016-12-10 18:09:00,729 INFO [org.apache.zookeeper.ClientCnxn] - Socket connection established to HadoopMaster/192.168.80.10:2181, initiating session
    2016-12-10 18:09:01,013 INFO [org.apache.zookeeper.ClientCnxn] - Session establishment complete on server HadoopMaster/192.168.80.10:2181, sessionid = 0x15825dedcf40031, negotiated timeout = 40000
    org.apache.hadoop.hbase.client.ClientScanner@12f8288e
    keyvalues={row_01/f:name/1478104345828/Put/vlen=4/seqid=0}
    family:f
    col:name
    valueAndy
    keyvalues={row_02/f:name/1478104477628/Put/vlen=5/seqid=0}
    family:f
    col:name
    valueAndy2
    2016-12-10 18:09:02,563 INFO [org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation] - Closing zookeeper sessionid=0x15825dedcf40031
    2016-12-10 18:09:03,395 INFO [org.apache.zookeeper.ZooKeeper] - Session: 0x15825dedcf40031 closed
    2016-12-10 18:09:03,419 INFO [org.apache.zookeeper.ClientCnxn] - EventThread shut down

  • 相关阅读:
    vivado工程移植
    Search Everything 多项查找
    RTL_代码覆盖率
    在ARTIX-7上实现摄像头视频通路
    转:自动生成testbench
    转:winedt中显示中文
    Zynq和microblaze的区别
    转:找不到include xgpio.h;Unresolved include xgpio.h
    DHTMLX 常用技术
    Ubuntu中安装 mercurial – TortoiseHG
  • 原文地址:https://www.cnblogs.com/zlslch/p/6156343.html
Copyright © 2011-2022 走看看