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

  • 相关阅读:
    SpringCloud之初入江湖
    消息中间件RabbitMQ
    分布式搜索引擎ElasticSearch
    MongoDB简介
    SpringBoot和SpringCloud版本对应
    终于有人把Elasticsearch原理讲透了!
    nginx不停服,重新加载配置
    小程序自定义头部标题栏并且自适应各种手机屏幕(滚动头部渐隐渐现)
    Navicat链接数据库报错1130解决方案
    传统的小程序登录 和 云开发小程序登录
  • 原文地址:https://www.cnblogs.com/leeeee/p/7276393.html
Copyright © 2011-2022 走看看