该异常为要自增的字段不为数字类型,所以调用incrementColumnValue方法会报错
首次put时指定为long字段:
put.add(Bytes.toBytes("cf"),Bytes.toBytes("count"), Bytes.toBytes( 1l)); //1后边有个l
再次自增:
table.incrementColumnValue("rowkey1".getBytes(),"cf".getBytes(),"count".getBytes(),1);
查询:
byte[] b;
long temp;
long res;
for (Result r : rs) {
if(new String(r.getRow()).equals("rowkey1")){
for (KeyValue keyValue : r.raw()) {
b =keyValue.getValue();
temp = 0;
res = 0;
for (int i=0;i<8;i++) {
res <<= 8;
temp = b[i] & 0xff;
res |= temp;
}
System.out.println(res);
}
}
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29754888/viewspace-1703713/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29754888/viewspace-1703713/