Java-put数据
HTableInterface table = null;
try {
table = hConnection.getTable(table_switch.getBytes()); //表
Put p = new Put("info".getBytes(Charset.forName("UTF-8"))); //列
p.add("info".getBytes(), null, historySwitch.getBytes(Charset.forName("UTF-8")));//rowkey
table.put(p);
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage());
}finally {
if(table != null){
try {
table.close();
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage());
}
}
}
Java创建初始化static
static {
configuration = HBaseConfiguration.create();
configuration.set("hbase.zookeeper.property.clientPort",zkPort);//客户端访问zkport
configuration.set("hbase.zookeeper.quorum",zkCluster);//重要的也是必须设置的,启动zk的服务器列表,逗号分隔,cluster模式下必须设置,默认是localhost,hbase客户端也需要设置这个值去访问zk;
configuration.set(HConstants.ZOOKEEPER_ZNODE_PARENT,HBase_ZOOKeeperParentnode);
try {
hConnection = HConnectionManager.createConnection(configuration);
} catch (ZooKeeperConnectionException e) {
logger.error(e.getMessage());
e.printStackTrace();
}
}
Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
在windows下开发hadoop一直正常,但把hadoop集群升级到2.0版本以上,在eclipse下执行程序会报打不到 winutils.exe的错误,这是因为hadoop2.2没有发布winutils.exe造成的。本文讲解如何在windows下开发hadoop 2程序
下载:hadoop-common-2.2.0-bin-master.zip
配置HADOOP_HOME环境变量,如下图:
修改HBase默认存储版本数:
Shell:alter 'table', NAME => 'colum', VERSIONS => 10
Java:
删除表
hbase(main):024:0> disable 'scores'
hbase(main):025:0> drop 'scores'
Json
import :org.codehaus.jettison.json.JSONObject
obj.put 方法可以put多个JSONObject值 而不会出现\\自动的转意斜线。
jsonObj.get / getString 方法可以很方便的得到对象的键值。
在Play中使用。