apl 连接hbase数据库

public class Getconnection {
    public static void main(String[] args) {
        //创建连接配置对象
        Configuration conf = new Configuration();

        //添加配置参数
        conf.set("hbase.zookeeper.quorum","hadoop102,hadoop103,hadoop104");
        Connection connection = null;
        //创建连接
        try {
            connection = ConnectionFactory.createConnection(conf);

        } catch (IOException e) {
            e.printStackTrace();
        }

        //创建一步连接
        CompletableFuture<AsyncConnection> asyncConnection = ConnectionFactory.createAsyncConnection(conf);

        //使用连接
        System.out.println(connection);

        //关闭连接
        try {
            connection.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

 

posted @ 2022-09-22 15:04  软工小蜗牛  阅读(69)  评论(0编辑  收藏  举报