Hbase访问 配置信息直接写在程序中的访问方式
2018-01-28 15:03
351 查看
public class HbaseInit{
private String QUORUM = "*****";
private String CLIENTPORT = "2015";
private Configuration conf = null;
private static HConnection conn = null;
static{
System.setProperty("HADOOP_USER_NAME", "sousuo");
}
public Map<String, String> getMapFromHbase(String tableName, String rowKey){
Map<String, String> hbaseRes = new HashMap<String, String>();
conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", QUORUM);
conf.set("hbase.zookeeper.property.clientPort", CLIENTPORT);
conf.set("zookeeper.znode.parent", "/hbase");
conf.set("hbase.client.retries.number", "2");
conf.set("hbase.client.pause", "100");
conf.set("zookeeper.recovery.retry", "3");
conf.set("zookeeper.session.timeout", "1000");
conf.set("zookeeper.recovery.retry.intervalmill", "200");
conf.set("ipc.socket.timeout", "2000");
conf.set("hbase.rpc.timeout", "2000");
conf.set("hbase.client.scanner.timeout.period", "5000");
conf.set("hbase.client.operation.timeout", "5000");
try {
logger.info("取表前++++++++++++++++++++++++++++++++++++++++++");
conn = HConnectionManager.createConnection(conf);
HTable table = new HTable(conf, tableName);
logger.info("取表后++++++++++++++++++++++++++++++++++++++++++");
Get get = new Get(Bytes.toBytes(rowKey));
Result result = table.get(get);
for (KeyValue rowKV : result.raw()) {
System.out.print("行名:" + new String(rowKV.getRow()) + " ");
System.out.print("时间戳:" + rowKV.getTimestamp() + " ");
System.out.print("列族名:" + new String(rowKV.getFamily()) + " ");
System.out.print("列名:" + new String(rowKV.getQualifier()) + " ");
System.out.println("值:" + new String(rowKV.getValue()));
hbaseRes.put("*******", new String(rowKV.getValue()));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return hbaseRes;
}
}
private String QUORUM = "*****";
private String CLIENTPORT = "2015";
private Configuration conf = null;
private static HConnection conn = null;
static{
System.setProperty("HADOOP_USER_NAME", "sousuo");
}
public Map<String, String> getMapFromHbase(String tableName, String rowKey){
Map<String, String> hbaseRes = new HashMap<String, String>();
conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", QUORUM);
conf.set("hbase.zookeeper.property.clientPort", CLIENTPORT);
conf.set("zookeeper.znode.parent", "/hbase");
conf.set("hbase.client.retries.number", "2");
conf.set("hbase.client.pause", "100");
conf.set("zookeeper.recovery.retry", "3");
conf.set("zookeeper.session.timeout", "1000");
conf.set("zookeeper.recovery.retry.intervalmill", "200");
conf.set("ipc.socket.timeout", "2000");
conf.set("hbase.rpc.timeout", "2000");
conf.set("hbase.client.scanner.timeout.period", "5000");
conf.set("hbase.client.operation.timeout", "5000");
try {
logger.info("取表前++++++++++++++++++++++++++++++++++++++++++");
conn = HConnectionManager.createConnection(conf);
HTable table = new HTable(conf, tableName);
logger.info("取表后++++++++++++++++++++++++++++++++++++++++++");
Get get = new Get(Bytes.toBytes(rowKey));
Result result = table.get(get);
for (KeyValue rowKV : result.raw()) {
System.out.print("行名:" + new String(rowKV.getRow()) + " ");
System.out.print("时间戳:" + rowKV.getTimestamp() + " ");
System.out.print("列族名:" + new String(rowKV.getFamily()) + " ");
System.out.print("列名:" + new String(rowKV.getQualifier()) + " ");
System.out.println("值:" + new String(rowKV.getValue()));
hbaseRes.put("*******", new String(rowKV.getValue()));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return hbaseRes;
}
}
相关文章推荐
- Struts2的国际化、配置全局资源与输出国际化信息、国际化—JSP中直接访问某个资源文件
- 当程序用ado的jet4.0方式连接的时候,对于设有access数据库密码的mdb的访问居然报错“无法启动应用程序,工作组信息文件丢失,或是已被其他用户已独占方式打开”,而用odbc方式不报错,小阴沟里翻船,郁闷中然后查文档解决之
- 模拟的nginx 配置为域名的的方式直接访问项目
- 当程序用ado的jet4.0方式连接的时候,对于设有access数据库密码的mdb的访问居然报错“无法启动应用程序,工作组信息文件丢失,或是已被其他用户已独占方式打开”,而用odbc方式不报错,小阴沟里翻船,郁闷中然后查文档解决之
- VisualGDB系列9:配置VS直接通过SSH方式访问Linux项目
- 当程序用ado的jet4.0方式连接的时候,对于设有access数据库密码的mdb的访问居然报错“无法启动应用程序,工作组信息文件丢失,或是已被其他用户已独占方式打开”,而用odbc方式不报错,小阴沟里翻船,郁闷中然后查文档解决之
- 轻松加密ASP.NET 2.0 Web程序配置信息
- 在远程桌面服务中配置RD网关直接访问内网
- 配置防火墙客户和Web代理客户的直接访问
- [Web]配置IIS,启动失败“另一个程序正在使用此文件,进程无法访问”
- centos7+mysql+svn(https方式访问)通过外网访问的配置
- 【札记】spring+mybatiss+c3p0整合访问MySQL的URL配置(有批量修改信息时)
- Hbase访问方式
- 【转贴】在Solaris中使用用户态程序直接访问I/O端口 - 上海嵌入式家园 贺工
- Android studio 3.01中的安卓程序以类的方式访问MySQL数据库
- 程序中通过wap联网方式访问网络
- spring配置静态资源访问的3种方式
- 微信小程序 项目实战(一)生命周期 配置服务器信息 splash启动页
- 微信公众号网页能够访问,但注册信息发送不到配置好的接口
- 配置weblogic的上下文,让浏览器直接通过ip地址访问