栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 前沿技术 > 大数据 > 其他

PhoenixJDBC

其他 更新时间:发布时间: 百科书网 趣学号
PhoenixJDBC 1.在pom.xml中加载phoenix依赖
	    
            org.apache.phoenix
            phoenix-core
            4.15.0-Hbase-1.4
        
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();
    }
}
转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/279540.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号