springboot-使用phoeinx连接hbase

1.pom.xml 加上对应版本

        
            org.apache.phoenix
            phoenix-core
            4.14.0-HBase-1.2
        

2.resources 目录下 添加hbase配置文件 hbase-site.xml

3.使用示例

    @RequestMapping("/test1")
    @ResponseBody
    public Map test1() throws ClassNotFoundException, SQLException {

        String driver = "org.apache.phoenix.jdbc.PhoenixDriver";
        Class.forName(driver);

        String phoenix_url = "xxxxxxx";
        String use = "xxx";
        String password = "xx";

        Connection conn = DriverManager.getConnection(phoenix_url,use,password);

        String sql = "select 字段1,字段2 from 表名 where pk='xxx'";
        PreparedStatement ps = conn.prepareStatement(sql);

        ResultSet rs = ps.executeQuery();
        List> list = new ArrayList<>();
        list = new ArrayList<>();
        //移动光标,如果新的当前行有效,则返回 true;如果不存在下一行,则返回 false
        while (rs.next()) {
            ResultSetMetaData rsmd = rs.getMetaData();
            Map map = new HashMap<>();
            for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                map.put(toLowerCase(rsmd.getColumnName(i)), rs.getObject(i));
            }
            list.add(map);
        }
        rs.close();
        ps.close();

        Map map = new HashMap<>(100000);
        map.put("data", list);
        return map;
    }

你可能感兴趣的:(springboot-使用phoeinx连接hbase)