在集群中Java 通过调用API操作HBase 0.98(2)

/**
  * get a data
  * @param configuration Configuration
  * @param tableName String,Table's name
  * */
 public static void getData(Configuration configuration,String tableName){
  HTable table;
  try {
   table = new HTable(configuration, tableName);
   Get get=new Get(Bytes.toBytes("zhangsan"));
   Result result=table.get(get);
 
   for(Cell cell:result.rawCells()){   
    System.out.println("RowName:"+new String(CellUtil.cloneRow(cell))+" ");
    System.out.println("Timetamp:"+cell.getTimestamp()+" ");
    System.out.println("column Family:"+new String(CellUtil.cloneFamily(cell))+" ");
    System.out.println("row Name:"+new String(CellUtil.cloneQualifier(cell))+" ");
    System.out.println("value:"+new String(CellUtil.cloneValue(cell))+" ");
   }
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
 
 /**
  * insert all data
  * @param configuration Configuration
  * @param tableName String,Table's name
  * */
 public static void getAllData(Configuration configuration,String tableName){
  HTable table;
  try {
   table=new HTable(configuration, tableName);
   Scan scan=new Scan();
   ResultScanner results=table.getScanner(scan);
   for(Result result:results){
    for(Cell cell:result.rawCells()){   
     System.out.println("RowName:"+new String(CellUtil.cloneRow(cell))+" ");
     System.out.println("Timetamp:"+cell.getTimestamp()+" ");
     System.out.println("column Family:"+new String(CellUtil.cloneFamily(cell))+" ");
     System.out.println("row Name:"+new String(CellUtil.cloneQualifier(cell))+" ");
     System.out.println("value:"+new String(CellUtil.cloneValue(cell))+" ");
    }
   }
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
   
 }
}

ant脚本

<?xml version="1.0"?> 
<project default="run" basedir="."> 
<!-- properies --> 
    <property value="src" /> 
    <property value="report" /> 
    <property value="classes" /> 
    <property value="lib" /> 
    <property value="dist" /> 
<property value="doc"/> 
    <!-- 定义classpath --> 
    <path> 
     <!--这边指向的jar包就是hbase 0.98 lib目录下对应的jar包,当前项目是把这些jar包放在项目的lib目录下-->
        <fileset file="${lib.dir}/*.jar" /> 
        <pathelement path="${classes.dir}"/> 
    </path> 
 
 <path> 
  <path path="${classes.dir}"/>
          <path refid="master-classpath" />
      </path>
    <!-- 初始化任务 --> 
    <target depends="clean">
     <mkdir dir="${classes.dir}"/>
     <mkdir dir="${dist.dir}"/>
    </target> 
    <!-- 编译 --> 
    <target depends="init" description="compile the source files"> 
         
        <javac srcdir="${src.dir}" destdir="${classes.dir}" target="1.7" includeantruntime="false"> 
            <classpath refid="master-classpath"/> 
        </javac> 
    </target> 
 
 <target depends="compile">
        <java classname="com.wan.hbase.SimpleHBase" classpathref="run.path" fork="true" >
        </java>
    </target>
 
    <!-- 打包成jar --> 
    <target depends="compile" description="make .jar file"> 
      <mkdir dir="${dist.dir}" /> 
        <jar destfile="${dist.dir}/hbaseproject.jar" basedir="${classes.dir}"> 
            <exclude /> 
            <exclude /> 
        </jar> 
    </target> 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/fa9ee1a9d26977a46cfcc941c4653e2a.html