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

  • 相关阅读:
    [转]Java中fina以及static的意义
    [转]Java中this的意义
    [转]Java中子类调用父类构造方法的问题分析
    [原创]SSH中HibernateTemplate与HibernateDaoSupport关系
    [转]No configuration found for the specified action解决办法
    [原创]MyEclipse2014全手动实现反向工程---解决手动整合ssh时发生的、在hibernate反向工程的时候找不到项目名的问题
    [转]SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
    pycharm中运行时添加配置 及pytest模式怎么修改为run模式
    字符串正则匹配替换
    PyCharm选中文件夹新建时Directory与Python package的区别
  • 原文地址:https://www.cnblogs.com/leeeee/p/7276393.html
Copyright © 2011-2022 走看看