开发者

How can I get get values outside this while loop in JSP?

How can I get get values outside this while loop in JSP. The code is as follows:

<%stat3=conn.createStatement();
rsobj=stat3.executeQuery(que开发者_高级运维ry1);
while(rsobj.next()) {
    int charge = Integer.parseInt(rsobj.getString(4));
    rate1=charge+rate1; %>    
    <tr>  
    <td  class="label" colspan="3" align="left">Net Amount Payable</td>
    <td class="database"  align="left"><%=rate1%></td>
</tr>
<tr>  
    <td  class="label" colspan="3" align="left">Due Amount</td>
    <td class="database"  align="left"><%=rsobj.getString(6)%></td>
</tr>
<%}%>

As this is a while loop but I want only rate1 i.e. total sum of amount to display in my program. I am not getting how could i do this. The above code displays all the values in the loop.


Just print that row only when the loop is finished?

<%stat3=conn.createStatement();
rsobj=stat3.executeQuery(query1);
while(rsobj.next()) {
    int charge = Integer.parseInt(rsobj.getString(4));
    rate1=charge+rate1; %>    
<tr>  
    <td  class="label" colspan="3" align="left">Due Amount</td>
    <td class="database"  align="left"><%=rsobj.getString(6)%></td>
</tr>
<%}%>
<tr>  
    <td  class="label" colspan="3" align="left">Net Amount Payable</td>
    <td class="database"  align="left"><%=rate1%></td>
</tr>

Needless to say that doing the DB access inside a JSP is a pretty terrible design approach.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜