如何用hive api导入数据
Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
Connection con = DriverManager.getConnection("jdbc:hive://192.168.191.17:10000/default", "", "");
Statement stmt = con.createStatement();
String sql = "LOAD DATA LOCAL INPATH '/data/mf/hzip/tmp/gamecoins' INTO TABLE gamecoins_stream";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
System.out.println(rs.getInt(0));
}
rs.close();
stmt.close();
con.close();
?
注意:这个文件的路径是要在开启以下命令的机器上
[hadoop@Hadoop-10-1 hive]$ bin/hive --service hiveserver &
?
否则,执行时会出现文件路径不存在的情况:
HiveServerException(message:Query returned non-zero code: 40000, cause:?
FAILED: SemanticException Line 1:23 Invalid path ''/data/mf/hzip/tmp/gamecoins'':?
No files matching path file:/data/mf/hzip/tmp/gamecoins, errorCode:40000, SQLState:42000)
?