我正在創始檢查空結果的解決方案...這裏是代碼檢查空結果
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