java連接hiveserver2


public class App {
	private static String driverName = "org.apache.hive.jdbc.HiveDriver";

	public static void main(String[] args) throws SQLException {

		try {

			Class.forName(driverName);

		} catch (ClassNotFoundException e) {

			e.printStackTrace();

			System.exit(1);

		}

		Connection con = DriverManager.getConnection(
				"jdbc:hive2://hostname:10000/dataplat", "hive", "");

		Statement stmt = con.createStatement();

		String sql = " select countertype,cppadate,count(1) from Hive_DataCpzCppaImeiCounter_real where cppadate>='2016-01-07' group by countertype,cppadate";
		ResultSet res = stmt.executeQuery(sql);

		while (res.next()) {

			System.out.println(res.getString(1) + "\t" + res.getString(2));

		}
		
		
	}
}

重點在getConnection的時候,要把你hive帳號傳過去,不然會說沒有權限操作。

另外吐嘈一下,在java端是沒有詳情的錯誤日志的,錯誤日志只能看hive-server2的日志,我使用的是cdh,日志在/var/log/hive/hadoop-cmf-hive-HIVESERVER2-hostname.log.out

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM