jdbc连接hive(hiveserver2)

import java.sql.*;

/**
 * Created by zheng on 2020/4/9.
 */
public class HiveClient {
    public static void main(String[] args) throws SQLException {
        try {
            Class.forName("org.apache.hive.jdbc.HiveDriver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.exit(1);
        }
        Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "zheng", "");
        Statement stmt = con.createStatement();
        ResultSet resultSet = stmt.executeQuery("show databases" );
        System.out.println(resultSet.toString());
    }
}

发现连接不上,原因是没有启动hiveserver2服务

#进入hive的bin目录
$ cd /Users/zheng/hive/hive-3.1.2/bin
#启动hivever2
$ hiveserver2

启动如果还是报错,参考:https://blog.csdn.net/zheng911209/article/details/105422908

你可能感兴趣的:(hive)