java的api從hbase中讀資料
package hbase.com.cn.hbase;
import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.HTable; 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 TestHBase {
static Configuration conf=null;
static Connection conn=null;
public static void getConnection() {
conf=HBaseConfiguration.create();
conf.set(“hbase.zookeeper.quorum”, “centos01:2181,centos02:2181,centos03:2181”);
try {
conn = ConnectionFactory.createConnection(conf);
//table=(HTable)conn.getTable(TableName.valueOf(“user_info”));
} catch (IOException e) {
e.printStackTrace();
}
}
public static void deletetable() throws Exception {
HTable table=new HTable(conf,Bytes.toBytes(“user_info”));
Listlist=new ArrayList<>();
for(int i=0;i<10;i++) {
Delete delete=new Delete((“baiyc_20150716_000”+i).getBytes());
if(i%2==0) {
delete.addColumn(“base_info”.getBytes(), “age”.getBytes());
}else {
//行簇 baiyc_20150716_000i 列簇 base_info 欄位 name
delete.addColumn(“base_info”.getBytes(), “name”.getBytes());
}
list.add(delete);
}
table.delete(list);
}
public static void scandata() throws Exception {
HTable table=new HTable(conf,Bytes.toBytes(“user”));
Scan scan=new Scan();//不傳參全表掃描
//Scan scan=new Scan(“rk001”.getBytes());
}