高手救急啊!!!如何判断数据库(表)中的内容为空(写出一个语句)?

来源:百度知道 编辑:UC知道 时间:2024/06/18 00:26:06

/*
* 判断表_command中是否存有命令
*/
@Override
public boolean ifExistsCommand() {
String query_sql = "select Count(*) from _command ; ";
Connection conn = DB.createConn();
PreparedStatement ps = DB.prepare(conn, query_sql);
ResultSet rs = null;
try {
rs = ps.executeQuery(query_sql);
} catch (SQLException e) {
e.printStackTrace();
}

int rows = 0;
if(null!=rs)
{
try {
while(rs.next()){
rows = rs.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
DB.close(ps);
DB.close(conn);
if (rows > 0) {
return true;//当查询的结果不为空时返回true
} else {
return false;
}
}