最简单的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        \t a \t  b \t c \t 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 + "\t" + a + "\t" + b + "\t" + c + "\t" + 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
1000010 20 30 50 70
1000011 22 33 55 77
1000012 24 36 60 84
1000013 26 39 65 91
1000014 28 42 70 98
1000015 30 45 75 105
1000016 32 48 80 112
1000017 34 51 85 119
1000018 36 54 90 126
1000019 38 57 95 133
1000020 40 60 100 140
1000021 42 63 105 147
1000022 44 66 110 154
1000023 46 69 115 161
1000024 48 72 120 168
1000025 50 75 125 175
1000026 52 78 130 182
1000027 54 81 135 189
1000028 56 84 140 196

转载于:https://www.cnblogs.com/leeeee/p/7276393.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值