用同样的查询条件去做一次统计吧,用sum
解决方案 »
- HibernateUtil工具类是在service层注入到impl好还是在impl中new出来直接使用好?
- JDBC+Struts+Spring高级查询
- hibernate
- 集成 spring + hibernate + struts 数据库映射问题 找不到数据库表
- 请问安装一下Oracle需要多大的硬盘空间!
- applet的问题
- Struts问题,关于调用JavaScript对<html:text>进行限制,以控制用户输入。
- BMP的简单问题(100)
- 请问这个功能该如何实现?
- 如何生成ejb.jar文件?
- spring中关于Connection的关闭
- wsdl2java最基本转化~有哪位大大能给个最基本的代码吗~
double sum=0;while(result.next())
{%> <%
if(isempty) {%>
<% isempty = false; %> <tr>
<th>财务月份 </th>
<th>发生日期 </th>
<th>费用类型 </th>
<th>项目类型 </th>
<th>项目归属 </th>
<th>费用科目 </th>
<th>科目明细 </th>
<th>报销人 </th>
<th>部门 </th>
<th>金额 </th>
<th>归属 </th>
<th>录入人员 </th>
<th>摘要 </th>
</tr>
<%} %>
<tr>
<%String id=result.getString("id"); %> <td> <%=result.getString(4)%> </td>
<td> <%=result.getString(5)%> </td>
<td> <%=result.getString(6)%> </td>
<td> <%=result.getString(7)%> </td>
<td> <%=result.getString(8)%> </td>
<td> <%=result.getString(9)%> </td>
<td> <%=result.getString(10)%> </td>
<td>
<%=result.getString(2)%> </td>
<td> <%=result.getString(3)%> </td>
<td> <%=result.getString(11)%> </td>
<td> <%=result.getString(12)%> </td> <td> <%=result.getString(14)%> </td>
<td> <%=result.getString(13)%> </td>
</tr>
<%
String money=result.getString(11);//把数据库中的money对就的字符串读出来
sum+=Double.valueOf(money); //转成double类型,加到sum里
}%>
<tr><td>总金额为<%=sum%></td></tr>
</table>
<br/>
<%
result.close();
stat.close();
con.close();
}
catch(Exception e)
{
out.println(e);
}
%> </div>
<div>
<%if(isempty) {%>
<%="没有要处理的内容" +" <br/>"%>
<% }%>
可以在你的代码的基础上加点东西就可以了
<%
BigDecimal zje = new BigDecimal("0");//在while循环之外定义变量总金额
%>
----------下面的是加入到while循环的结尾处
</tr>
<%
//11是金额吧?这是我数出来的,我都能数到11了,不容易啊
zje =zje.add(new BigDecimal((String)result.getString(11)));
}//这个大括号是while的结尾
%>最后在你想要输出的地方输出总金额就可以了。
别忘了在前面引用BigDecimal,java.math.BigDecimal
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String ConnStr="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\myweb\\datebase.mdb";
Connection con = DriverManager.getConnection(ConnStr);
String scribe;
byte[] temp;
scribe = request.getParameter("name1");
temp = scribe.getBytes("iso8859-1");
scribe = new String(temp);
String name = scribe;
PreparedStatement stat=con.prepareStatement(
"select sum(jine) from show where dpt='"+name+"'");
ResultSet result=stat.executeQuery();
while(result.next())
(
out.print(总金额???);//这里怎么输出总金额
result.close();
stat.close();
con.close();}
catch(Exception e)
{
out.println(e);
}
楼主试试