上面直接介绍了druid访问hbase phoenix的案例hbase Phoenix整合mybatis DruidDataSource
这里还是贴一下jdbc直接访问的方式。public static void main(String[] args) {
try {
Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
Properties properties=new Properties();
properties.setProperty("phoenix.query.timeoutMs", "1200000");
properties.setProperty("hbase.rpc.timeout", "1200000");
properties.setProperty("hbase.client.scanner.timeout.period", "1200000");
Connection conn = DriverManager.getConnection("jdbc:phoenix:master,slave1",properties);
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select count(1) from itxw.table");
int count = 0;
if(rs.next()) {
count=rs.getInt(1);
System.out.println("count:"+count);
}
conn.commit();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
需要注意其中配置的超时时间,否则phoenix只有60秒就会超时,当然服务端也要相应的配置。
还有如果phoenix配置了事务,需要显示的调用commit来提交。