我正在寻找一个检查空结果集的解决方案......这是代码
temp = rs1;
boolean hasRows = temp.next();
if (hasRows) {
while (rs1.next()) {
String pid = rs1.getString("pid");
System.out.println(pid);
String pd = rs1.getString("description");
double price = rs1.getDouble("price");%>
<br>
Product id : <%=pid %><br>
Description : <%=pd %><br>
Price : <%=price %>
<%
}
}
看来temp.next()
会影响rs.next(),最终结果无法打印出来。为什么?
最佳答案
next()
方法已经检查您尝试的控件。如果结果集 rs1 包含元素,则将进入循环。
您似乎没有在任何地方使用 temp
。为什么?放弃它并完成你的工作,试试这个:
boolean loopEntered = false;
while (rs1.next())
{
loopEntered = true;
String pid = rs1.getString("pid");
System.out.println(pid);
String pd = rs1.getString("description");
double price = rs1.getDouble("price");
%>
<br>
Product id : <%=pid %><br>
Description : <%=pd %><br>
Price : <%=price %>
<%
}
if(!loopEntered)
// print your error messages.
关于java - 检查空结果集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9358038/