2014-03-27 1 views
1

java api를 사용하여 독립 실행 형 모드 (Hadoop없이)로 Hbase에 연결할 수 있습니까?java api를 사용하여 Hbase에 연결하지 못했습니다.

여기 내 코드입니다. 어떻게 작동하게할까요? 변수 'config'에 속성을 설정해야합니까?

나는이 로컬로 설치 한 : HBase를-0.98.0 하둡 2.2.0

import java.io.IOException; 

import org.apache.hadoop.conf.Configuration; 
import org.apache.hadoop.fs.Path; 
import org.apache.hadoop.hbase.HBaseConfiguration; 
import org.apache.hadoop.hbase.client.Get; 
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 MyLittleHBaseClient { 
    public static void main(String[] args) throws IOException { 

    // maybe I should do some configuration here, but I don't know how 
    Configuration config = HBaseConfiguration.create(); 

    HTable table = new HTable(config, "myLittleHBaseTable"); 

    Put p = new Put(Bytes.toBytes("myLittleRow")); 

    p.add(Bytes.toBytes("myLittleFamily"), Bytes.toBytes("someQualifier"), 
     Bytes.toBytes("Some Value")); 

    table.put(p); 

    Get g = new Get(Bytes.toBytes("myLittleRow")); 
    Result r = table.get(g); 
    byte [] value = r.getValue(Bytes.toBytes("myLittleFamily"), 
     Bytes.toBytes("someQualifier")); 

    String valueStr = Bytes.toString(value); 
    System.out.println("GET: " + valueStr); 

    Scan s = new Scan(); 
    s.addColumn(Bytes.toBytes("myLittleFamily"), Bytes.toBytes("someQualifier")); 
    ResultScanner scanner = table.getScanner(s); 
    try { 

     for (Result rr = scanner.next(); rr != null; rr = scanner.next()) { 

     System.out.println("Found row: " + rr); 
     } 

    } finally { 

     scanner.close(); 
    } 
    } 
} 
+0

이 속성을 HbaseConfiguration 객체'hbase.zookeeper.quorum'로 설정할 수 있습니까 – donut

+0

실행 해 보았습니까? 프로그램이 나에게 맞는 것 같습니다. –

답변

0

독립형 모드에서 HBase를-site.xml의가) (비어있는 경우, 당신은 어떤 일을 설정할 필요가 없습니다 . hbase-site.xml에서 아무 것도 재정의했으면 매개 변수를 별도로 설정하는 대신 hbase-site.xml을 더 추가하는 것이 좋습니다.

Configuration config = HBaseConfiguration.create(); 
config.addResource("<HBASE_CONF_DIR_PATH>/hbase-site.xml"); 
+0

정말로 도움이되는 답변을 주셔서 감사 드리며 여기에 또 다른 문제가 있습니다. 잠시 살펴볼 수 있습니까? http://stackoverflow.com/questions/22710112/get-error-when-i-use-java-api-to-connect-hbasestandalone-mode-without-hadoop –

관련 문제