java如何检测SQL查询结果为空
2个回答
展开全部
public static boolean checkCountExecute(String sql) {
Connection conn = getConnection();
Statement st = null;
ResultSet rs = null;
boolean flag = false;
try {
st = conn.createStatement();
rs = st.executeQuery(sql);
if (rs.next()) {
flag = true;
} else {
flag = false;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBConnection.tryClose(conn, st, null, null);
}
return flag;
}
判断是否有结果的一个通用方法0.0
Connection conn = getConnection();
Statement st = null;
ResultSet rs = null;
boolean flag = false;
try {
st = conn.createStatement();
rs = st.executeQuery(sql);
if (rs.next()) {
flag = true;
} else {
flag = false;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBConnection.tryClose(conn, st, null, null);
}
return flag;
}
判断是否有结果的一个通用方法0.0
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询