* 判断表_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
}
}
T-SQL代码:
IF (NOT EXISTS(SELECT * FROM [表名])) PRINT '这是一个空表'解释:
EXISTS() //如果查询到数据返回true, 否则返回false
PRINT //输出信息
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)