连接hive查询

  1. pom.xml (来源: https://blog.csdn.net/niityzu/article/details/42639369)

    1.2.1
    1.2.1
    1.2.1
    1.2.1
    0.9.3
    2.7.1
    4.5.3
    4.4.6



    org.apache.hive
    hive-jdbc
    {hive-exec.version}


    org.apache.hive
    hive-metastore
    {hive-service.version}


    org.apache.thrift
    libfb303
    {hadoop-common.version}


    org.apache.httpcomponents
    httpclient
    {httpcore.version}

  2. 代码
    public class HiveUtil {

    public static Connection getHiveCon() throws ClassNotFoundException, SQLException {
    Connection connection = null;
    Class.forName("org.apache.hive.jdbc.HiveDriver");
    connection = DriverManager.getConnection("jdbc:hive2://ip:21050/;auth=noSasl", "账号", "");
    return connection;
    }

    public static void main(String[] args) throws SQLException, ClassNotFoundException {
    Statement stmt = HiveUtil.getHiveCon().createStatement();
    String sql = " select count(*) from 数据库.表 WHERE dt='20190304' ";
    String rest = "";
    ResultSet res = stmt.executeQuery(sql);
    while (res.next()) {
    rest = res.getString(1);
    System.out.println(rest);
    }
    }
    }

你可能感兴趣的:(连接hive查询)