如何检查特定表是否表示表A在hive中是空的。我需要将其作为布尔值存储到我的java代码中的变量。我试过这个
Statement stmt = con.createStatement();
stmt.execute("Select count(*) from "+tableName);
int ct = stmt.getUpdateCount();
logger.info("Hive Table count is " +ct);
if(ct > 0)
return false;
else
return true;
但这似乎不起作用。有什么建议吗?
答案 0 :(得分:0)
试试这个:
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select count(*) from "+tableName);
int ct = rs.getInt(0);
logger.info("Hive Table count is " +ct);
if(ct > 0)
return false;
else
return true;
答案 1 :(得分:-1)
你可以这样试试:
ResultSet resultSet;
resultSet = stmt.executeQuery("select * from "+tableName);
int count = 0;
while (resultSet.next()) {
count++;
}
if(count == 0) // Table is empty.