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
