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

  • 相关阅读:
    [FAQ] jsoneditor 如何切换 mode 或者选择 modes
    IDA动态调试快捷键
    [FAQ] PHP Warning: json_encode(): double INF does not conform to the JSON spec
    Git 工具下载慢问题 & 图像化界面工具
    Windows 查看端口是被什么程序占用
    什么是 objdump 命令
    什么是 IDA 工具
    什么是 ELF 文件(文件格式)
    ARM 反汇编速成
    [Mobi] Android Studio NDK 安装
  • 原文地址:https://www.cnblogs.com/leeeee/p/7276393.html
Copyright © 2011-2022 走看看