Phoenix安装+jdbc连接操作

Phoenix是hbase的一个皮肤,能够简化hbase的操作具体的安装教程在下面

Phoenix视频安装教程

下面是我链接jdbc进行数据查询的操作,和我最初操作MySQL时很像

首先仍然是导包

<dependency>
            <groupId>org.apache.phoenix</groupId>
            <artifactId>phoenix-client-hbase-2.4</artifactId>
            <version>5.1.2</version>
        </dependency>

 

代码

package com.it.Phoenix;

import java.sql.*;
import java.util.Properties;

public class PhoenixConnection {
    public static void main(String[] args) {
        //标准的jdbc连接
        //url
        String url = "jdbc:phoenix:hadoop102,hadoop103,hadoop104:2181";

        //配置对象
        Properties properties = new Properties();

        //获取链接
        try {
            Connection connection = DriverManager.getConnection(url);

            //编译sql
            PreparedStatement statement = connection.prepareStatement("select * from student");
            //执行sql
            ResultSet resultSet = statement.executeQuery();
            while (resultSet.next()) {
                System.out.println(resultSet.getString(1) + ":" + resultSet.getString(2) + ":" + resultSet.getLong(3) + ":" +
                        resultSet.getString(4));
            }

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

 

posted on 2022-09-23 22:53  跨越&尘世  阅读(487)  评论(0编辑  收藏  举报