PhoenixJDBC
1.在pom.xml中加载phoenix依赖
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>4.15.0-HBase-1.4</version>
</dependency>
2.获取Connection对象
Connection conn = DriverManager.getConnection("jdbc:phoenix:master,node1,node2:2181");
3.获取执行sql语句的对象 PreparedStatement
//使用PreparedStatement防止sql注入
PreparedStatement ps = conn.prepareStatement("select * from dianxin where end_date=?");
ps.setString(1,"20180503210524");
4.执行sql,接受返回结果
ResultSet rs = ps.executeQuery();
5.处理结果
while (rs.next()) {
String mdn = rs.getString("mdn");
String start_date = rs.getString("start_date");
String county = rs.getString("county");
String x = rs.getString("x");
String y = rs.getString("y");
System.out.println(mdn+"\t"+start_date+"\t"+county+"\t"+x+"\t"+y+"\t");
}
6.释放资源
ps.close();
conn.close();
7.整合
public class Demo8PhoenixJDBC {
public static void main(String[] args) throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:phoenix:master,node1,node2:2181");
PreparedStatement ps = conn.prepareStatement("select * from dianxin where end_date=?");
ps.setString(1,"20180503210524");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
String mdn = rs.getString("mdn");
String start_date = rs.getString("start_date");
String county = rs.getString("county");
String x = rs.getString("x");
String y = rs.getString("y");
System.out.println(mdn+"\t"+start_date+"\t"+county+"\t"+x+"\t"+y+"\t");
}
ps.close();
conn.close();
}
}