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

PhoenixJDBC

其他 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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.mshxw.com
本文地址:https://www.mshxw.com/it/279540.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号