zoukankan      html  css  js  c++  java
  • 最简单的Phoenix 访问 HBase例子

            String username = "";
            String password = "";
            String url = "jdbc:phoenix:10.1.20.129, 10.1.20.124, 10.1.20.44";
            Connection connection = null;
            Statement statement = null;
            ResultSet set = null;
            try {
                Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
                connection = DriverManager.getConnection(url, username, password);
                statement = connection.createStatement();
                statement.execute(" create table  if not exists test"
                        + "(id bigint not null primary key, cf1.a bigint , cf1.b bigint, cf2.c bigint , cf2.d bigint) ");
                for (int i = 10; i < 29; i++) {
                    statement.executeUpdate("upsert into test values (10000" + i + "," + i * 2 + "," + i * 3 + "," + i * 5 + "," + i * 7 + ")");
                }
                connection.commit();
                set = statement.executeQuery("  select id,   a,  b ,  c ,  d  from test   ");


                System.out.println("id         a  b c d");
                while (set.next()) {
                    Long id = set.getLong("id");
                    Long a = set.getLong("a");
                    Long b = set.getLong("b");
                    Long c = set.getLong("c");
                    Long d = set.getLong("d"); 
                    System.out.println(id + " " + a + " " + b + " " + c + " " + d);
                }
            } catch (SQLException ex) {
                Logger.getLogger(GetData.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(GetData.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                if (set != null) {
                    try {
                        set.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(GetData.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                if (statement != null) {
                    try {
                        statement.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(GetData.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                if (connection != null) {
                    try {
                        connection.close();
                    } catch (SQLException ex) {
                        Logger.getLogger(GetData.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }

        }


    打印:

    id          a  b c d
    100001020 305070
    100001122 335577
    100001224 366084
    100001326 396591
    100001428 427098
    100001530 4575105
    100001632 4880112
    100001734 5185119
    100001836 5490126
    100001938 5795133
    100002040 60100 140
    100002142 63105 147
    100002244 66110 154
    100002346 69115 161
    100002448 72120 168
    100002550 75125 175
    100002652 78130 182
    100002754 81135 189
    100002856 84140 196

  • 相关阅读:
    [Android]Parcelable encountered IOException writing serializable object (name = xxx)
    开机黑屏 仅仅显示鼠标 电脑黑屏 仅仅有鼠标 移动 [已成功解决]
    poj3070--Fibonacci(矩阵的高速幂)
    Java泛型解析(03):虚拟机运行泛型代码
    PHP中的替代语法
    在ubuntu上部署hadoop时出现的问题
    js闭包(函数内部嵌套一个匿名函数:这个匿名函数可将所在函数的局部变量常驻内存)
    js匿名函数(变量加括号就是函数)
    javascript进阶课程--第三章--匿名函数和闭包
    js实现科学计算机
  • 原文地址:https://www.cnblogs.com/leeeee/p/7276393.html
Copyright © 2011-2022 走看看