Actually James' for statement is gramatically correct. The center part
of a for statement is an expression that evaluates to a boolean (see the
java language specifications 14.12).

A common use is something like:

for (int i = 1; i < 10; i++) {

In this case i < 10 evaluates to a boolean, either i is less then 10
(true) or i is not less then 10 (false).

Now that I've gone way off topic, let me say that I agree that
while(results.next()) is a neater way to code this, but I don't think
that is why he is having the problem.

Carles

"Borkey, Lin" wrote:
>
> The problem is in
>
>     for (int i=1; results.next(); i++)  {
>
> results.next() returns a boolean, not an integer.  Use while(results.next())
> { instead.
>
>         ----------
>         From:  Griggs, James [SMTP:[EMAIL PROTECTED]]
>         Sent:  Tuesday, October 26, 1999 1:01 PM
>         To:  [EMAIL PROTECTED]
>         Subject:  jsp help
>
>         The following jsp page is only retrieving one row when it should be
> displaying several.  Our 3 jsp gurus have been unable to find the bug.  Can
> you ?
>
>         ------------------------------------------------
>
>         <%@ page import="java.util.*" %>
>         <%@ page import="java.sql.*" %>
>         <%@ page import="com.ngs.database.*" %>
>         <HTML>
>         <BODY>
>         <TABLE>
>         <TR>
>         <TD>
>         Stats
>         </TD>
>         </TR>
>         <%
>                 Connection con=null;
>                 Statement stmt=null;
>                 Statement stmt2=null;
>                 int id = Integer.parseInt( request.getParameter("user") );
>                 try
>               {
>                       ConnectString cstr = new
> OracleThinConnectString("montross.ngw.com", "ngen01");
>
>                       con = ConnectionFactory.buildConnection(cstr, "nn",
> "sh");
>
>                       stmt = con.createStatement();
>                       String totalsql = "select count(*) FROM request where
> userid = ?";
>
>                       PreparedStatement statement =
> con.prepareStatement(totalsql);
>
>                       statement.setInt(1, id);
>                       ResultSet results = statement.executeQuery();
>
>                       int total_requests = statement.results;
>                       statement.close();
>
>                               stmt2 = con.createStatement();
>
>                       String sqlstmt = "select requestid, comments," +
>
>                                     "createdt, closedt, responsecount,userid
> " +
>
>                                     "FROM request " +
>
>                                     "where userid = ?" +
>
>                                     "order by createdt desc";
>
>                       statement = con.prepareStatement(sqlstmt);
>                       statement.setInt(1, id);
>                       results = statement.executeQuery();
>
>                       for (int i=1; results.next(); i++)
>                       {
>                           int db_reqid = results.getInt(1);
>                           String db_comments = results.getString(2);
>
>                           String db_createdt = results.getString(3);
>
>                           String db_closedt = results.getString(4);
>
>                           int db_responsect = results.getInt(5);
>
>                           int db_user = results.getInt(6);
>         %>
>         <%
>                           if (i <= total_requests)
>                           {
>         %>
>         <tr>
>         <td>
>         <%=db_reqid%>
>         </td>
>         <td>
>         <%=db_comments%>
>         </td>
>         <td>
>         <%=db_createdt%>
>         </td>
>         <td>
>         <%=db_closedt%>
>         </td>
>         <td>
>         <%=db_responsect%>
>         </td>
>         </tr>
>         <tr><td align=center valign=middle colspan=5><hr></td></tr>
>         <%
>                                     } else
>
>                                     {
>
>         %>
>         <tr>
>         <td coslspan=2>
>         <font size=3 face="arial,helvetica">Total Requests:
> <b><%=total_requests%></b></font>
>         </td>
>         </tr>
>         <tr>
>         <td colspan=5 align=center>
>         <a href="/buyers/showbuyerprofile.html?user=<%=db_user%>">Return to
> Buyer Profile</a>
>         </td>
>         </tr>
>         <%
>                           }
>
>         %>
>
>         <%
>                           if ((i % total_requests) == 0)
>                           {
>         %>
>
>         <%
>                           }
>                       }
>                 } catch(Exception e)
>                 {
>         %>
>         <tr>
>         <td>
>         <H3>No Request History Available</h3><br> <%=e.getMessage()%>
>         </td></tr>
>         <%
>                 }
>         %>
>         </table>
>         </center>
>         </BODY>
>         </HTML>
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> FAQs on JSP can be found at:
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to