场景
我正在尝试通过 Zookeepers 集群从本地笔记本电脑连接到 Hive 表到远程开发服务器,并尝试更新表列值。 Hadoop 集群和 Hive 表也远程位于开发环境中。 我使用 hive-jdbc.jar 版本 2.1.0 和 hadoop-common 版本 2.7.1
问题
面临表记录已更新但 stmt.getUpdateCount() 和 stmt.executeUpdate 分别返回 -1 和 0 的问题。 代码: 有没有漏掉什么??或者在 Hive 表中 getUpdateCount() 的行为有所不同? 感谢任何快速帮助..
代码:
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException,
ClassNotFoundException {
Class.forName(driverName);
Connection con =
DriverManager.getConnection("jdbc:hive2://XXXX:XXXX/tibco,
XXXX:XXXX/tibco,XXXX:XXXX/tibco;
serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2;
"hive.execution.engine=tez", "hive", "");
Statement stmt = con.createStatement();
con.setAutoCommit(true);
System.out.println("created");
ResultSet rs = stmt.executeQuery("select * from tibco.log_events_poc");
ResultSet db1=stmt.executeQuery("desc tibco.log_events_poc");
System.out.println("tibco.log_events_poc table -->"+db1);
int rowsupdated = stmt.executeUpdate("update tibco.log_events_poc set
name='sample1'");
System.out.println("Number of Rows updated"+stmt.getUpdateCount());
System.out.println("Number of Rows updated"+rowsupdated);
stmt.close();
con.close();
}
请您参考如下方法:
You can check out the sources of version 2.1.0 。驱动程序完全忽略任何更新计数并始终返回0
:
@Override
public int executeUpdate(String sql) throws SQLException {
execute(sql);
return 0;
}