Centos6.5 64位 安装Hadoop2.7.0, MapReduce日志分析, Hive2.1.0, JDBC连接Hive查询 (4)

前端之家收集整理的这篇文章主要介绍了Centos6.5 64位 安装Hadoop2.7.0, MapReduce日志分析, Hive2.1.0, JDBC连接Hive查询 (4)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

第四篇 JDBC连接Hive查询


jdbc 连接hive 查询,要做以下几个事情,前面也曾提到:

1 在hadoop的core-site.xml 中增加配置

<property>
            <name>hadoop.proxyuser.root.groups</name>
            <value>*</value>
        </property>

        <property>
            <name>hadoop.proxyuser.root.hosts</name>
            <value>*</value>
        </property>

2 让hive支持自定义验证

http://www.jb51.cc/article/p-evbqggss-bhy.html


3 编写测试程序

package hive.server2.query;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class ApiQueryTest {
	private static String driverName = "org.apache.hive.jdbc.HiveDriver";
	private static final Logger logger = LogManager.getLogger("ApiQueryTest");

	public static void main(String[] args) {

		try {
			Class.forName(driverName);
			Connection con = null;
			con = DriverManager.getConnection("jdbc:hive2://10.68.128.215:10000","root","kangyun9413");
			Statement stmt = con.createStatement();
			ResultSet res = null;
			String sql = "select sum(num) total,url,status from apis.api_logs group by status,url order by total desc limit 10";
			System.out.println("Running: " + sql);
			res = stmt.executeQuery(sql);
			System.out.println("ok");
			while (res.next()) {
				System.out.println(res.getString(1) + "\t" + res.getString(2) + "\t" + res.getString(3));
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("error");
		}

	}
}

运行:

原文链接:https://www.f2er.com/centos/380738.html

猜你在找的CentOS相关文章