我正在创始检查空结果的解决方案...这里是代码检查空结果
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(),结果不能打印最后。为什么?
这是面向对象的。 'temp'引用与'rs'相同的'ResultSet'实例... – home 2012-02-20 08:28:39
@home这与面向对象无关,只是'temp'和'rs1'引用同一个对象。对于OP,使用'while(rs1.hasNext()){...}'。 – kba 2012-02-20 09:09:18
@Kristian Antonsen:它不一定与OO有关,但正如你所提到的,它指的是一个对象,我会调用指针或引用一个常见的OO原则。 – home 2012-02-20 09:18:06