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

  • 相关阅读:
    Django学习路10_创建一个新的数据库,指定列名并修改表名
    设计模式_单例模式的懒汉式实例化
    设计模式_理解单例设计模式
    Django学习路9_流程复习
    Django学习路8_学生表和班级表级联并相互查询信息
    Django学习路7_注册app到能够在页面上显示app网页内容
    es6基础:类、继承、重写
    简单的下拉刷新
    callback&&callback()
    转 五大浏览器四大内核
  • 原文地址:https://www.cnblogs.com/leeeee/p/7276393.html
Copyright © 2011-2022 走看看