Hive的JDBC访问
实现hive查询源码:
String driverName = "org.apache.hive.jdbc.HiveDriver";
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
}
Connection con = DriverManager.getConnection("jdbc:hive2://10.1.108.65:10000/default", "hive", "");
Statement stmt = con.createStatement();
//createAndSelectTable(stmt);
ResultSet res = stmt.executeQuery("select * from test limit 10");
while (res.next()) {
System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));
}
Invalid status 72
这个错误信息说明jdbc的url有错误;网上很多人发帖子说是hive2的端口是10002,后来发现在cloudera里面的hive2服务的端口是10000.
密码无所谓
至于jdbc里面的用户名和密码即使传“”,其实也无所谓。
浙公网安备 33010602011771号