public class Demo5 {
public static Configuration conf = HBaseConfiguration.create();
static {
Configuration HBASE_CONFIG = new Configuration();
HBASE_CONFIG.set("hbase.zookeeper.quorum",
"BJ-YZ-103R-63-38,BJ-YZ-103R-63-39,BJ-YZ-103R-63-40");
HBASE_CONFIG.set("hbase.zookeeper.property.clientPort", "2181");
conf = HBaseConfiguration.create(HBASE_CONFIG);
}
public static void QueryByCondition3(String tableName,String v1,String v2) {
try {
HTablePool pool = new HTablePool(conf, 1000);
HTableInterface table = pool.getTable(tableName);
List<Filter> filters = new ArrayList<Filter>();
Filter filter1 = new SingleColumnValueFilter(Bytes.toBytes("c1"), Bytes.toBytes("city"), CompareOp.EQUAL, Bytes.toBytes(v1));
filters.add(filter1);
Filter filter2 = new SingleColumnValueFilter(Bytes.toBytes("c1"), Bytes.toBytes("sex"), CompareOp.EQUAL, Bytes.toBytes(v2));
filters.add(filter2);
FilterList filterList1 = new FilterList(filters);
Scan scan = new Scan();
scan.setFilter(filterList1);
ResultScanner rs = table.getScanner(scan);
for (Result r : rs) {
System.out.println("获得到rowkey:" + new String(r.getRow()));
for (KeyValue keyValue : r.raw()) {
System.out.println("列:" + new String(keyValue.getFamily())
+ "====值:" + new String(keyValue.getValue()));
}
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException {
Demo5.QueryByCondition3("test1","hangzhou","nan");
}
}