我正在寫基於Java的Hbase客戶端的一些非常基本的東西,用於在啓用的現有表上執行掃描操作。該方案是基於: https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/package-summary.html來自Java的HBase掃描API
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Table;
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;
import org.apache.hadoop.hbase.protobuf.generated.*;
public class FirstHBaseClient {
public static void main(String[] args) throws IOException {
Configuration config = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(config);
try {
Table table = connection.getTable(TableName.valueOf("test"));
try {
Scan s = new Scan();
ResultScanner scanner = table.getScanner(s);
try {
for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
// print out the row we found and the columns we were looking for
System.out.println("Found row: " + rr);
}
} finally {
scanner.close();
}
} finally {
if (table != null) table.close();
}
} finally {
connection.close();
}
}
}
編譯和執行被罰款......會話建立得到。 但我沒有從掃描操作得到任何結果,爲什麼? Eclipse控制檯輸出:
15/09/17 19:37:18 INFO zookeeper.ZooKeeper: Client environment:user.dir=/root/workspace_hbase/HBaseIntro
15/09/17 19:37:18 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=90000 watcher=hconnection-0xea4a92b0x0, quorum=localhost:2181, baseZNode=/hbase
15/09/17 19:37:18 INFO zookeeper.ClientCnxn: Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
15/09/17 19:37:18 INFO zookeeper.ClientCnxn: Socket connection established to localhost/127.0.0.1:2181, initiating session
15/09/17 19:37:18 INFO zookeeper.ClientCnxn: Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x14fde0f7576000e, negotiated timeout = 40000
我在做什麼錯了? 我在Ubuntu Linux上使用Hbase-1.1.2版本並運行JDK1.8.x.
我嘗試過使用Apache Phoenix來做這件事......從松鼠而不是從我的Java代碼中工作得很好。 – Ashu
尚未在Hadoop中支持/認證JDK1.8。建議使用JDK7。 –