<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page 
        import="java.sql.*"
        import="java.util.*"
        import="javax.servlet.*"
        import="javax.servlet.http.*"
        import="com.xinchang.db.SQLBean_JDBC"
        import="com.xinchang.sinotrans.formbean.Sys_FormBean_Parameter"
%>        
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request.setCharacterEncoding("GBK");%>
<%
String stringSql="";
String chaxun=request.getParameter("chaxun");
if ( chaxun == null) {chaxun = "";}
if("查询".equals(chaxun)) {
String danhao=request.getParameter("danhao");
if ( danhao == null) {danhao = "";}

String tidanhao=request.getParameter("tidanhao");
if ( tidanhao == null) { tidanhao = "";}stringSql = "select  yewubaogaodanhao,tidanhao,tuoyunren,pinming,yichengchuanminghangci,yichengchuankaihangriqi"
+ "  from tuoyun where " + "  tidanhao like'%"+tidanhao+"%' " ;

if(danhao.length()>0){
stringSql=stringSql+ " and  yewubaogaodanhao like '%"+danhao+"%' ";
}

System.out.println("RRRRRRRRRRRRRRRRRRR"+stringSql);
}
%><html>
  <head>
    <base href="<%=basePath%>">
    
    <title>查询结果</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link media="all" href="xc.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body {
background-image: url(img/0004.gif);
}
body,td,th {
font-family: 宋体;
font-size: 12px;
}
</style>
</head>
<body>
<table width="800" border="0" align="center">
  <tr>
    <td bgcolor="#D4D0C7"><br>
      <table width="780" border="0" align="center" cellspacing="0">
      <tr>
        <td align="center"><h1>费用分割单</h1></td>
      </tr>
      </table>
      <br>
        <form active="fgdcx.jsp" method="post">
      <table width="450" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td width="70" height="25">报告单号</td>
          <td width="168"><input  name="danhao" class="wenbenkuang1" id="danhao" size="18" /></td>
          <td width="10">&nbsp;</td>
          <td width="70" >提单号</td>
          <td><input  name="tidanhao" class="wenbenkuang1" id="tidanhao" size="18" /></td>
          <td width="10">&nbsp;</td>
          <td width="49"><input type="submit" name="chaxun" value="查询" style="font-family: 宋体; font-size:9pt" /></td>
        </tr>
      </table>
</form>
      <br>
      <hr size=1 >
      <table width="780" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
        <tr>
          <th width="18%"  height="25" bgcolor="#999999" class="STYLE3">提单号</th>
          <th width="28%" bgcolor="#999999" class="STYLE3">结算单位</th>
          <th width="13%" bgcolor="#999999" class="STYLE3">毛重</th>
          <th width="29%" bgcolor="#999999" class="STYLE3">体积</th>
          <th width="12%" bgcolor="#999999" class="STYLE3">箱量</th>
        </tr>
<% 
    if("查询".equals(chaxun)) {
Statement stmt = null;
ResultSet rs1 = null;
Connection conn = null;
SQLBean_JDBC so = new SQLBean_JDBC(); try {
conn = so.getConnection();
stmt = conn.createStatement();
rs1 = stmt.executeQuery(stringSql); } catch (Exception ex) {
System.out.println("nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn"); }

while (rs1.next()){ try {
String bgd=rs1.getString("yewubaogaodanhao");
String tdh=rs1.getString("tidanhao");
String tyr=rs1.getString("tuoyunren");
String mz=rs1.getString("maozhong");
String tj=rs1.getString("tiji"); 
String xl=rs1.getString("xiangliang"); %>
        <tr>
          <td height="25" bgcolor="#CCCCCC" style= "cursor:pointer; "   onclick= "window.open( '<%=basePath %>luyun/fgd.jsp?bgd=<%=bgd %>&tdh=<%=tdh %>', '_blank')" >< %if(tdh!=null||tdh.length()<=10){out.print(tdh);}else{out.print(tdh.substring(0,10));} %></td>
          <td bgcolor="#CCCCCC" style= "cursor:pointer; "   onclick= "window.open( '<%=basePath %>luyun/fgd.jsp?bgd=<%=bgd %>&tdh=<%=tdh %>', '_blank')"><% if(tyr!=null){out.print(tyr.trim());} %></td>
          <td bgcolor="#CCCCCC" style= "cursor:pointer; "   onclick= "window.open( '<%=basePath %>luyun/fgd.jsp?bgd=<%=bgd %>&tdh=<%=tdh %>', '_blank')"><% if(mz!=null){out.print(mz.trim());} %></td>
          <td bgcolor="#CCCCCC" style= "cursor:pointer; "   onclick= "window.open( '<%=basePath %>luyun/fgd.jsp?bgd=<%=bgd %>&tdh=<%=tdh %>', '_blank')"><% if(tj!=null){out.print(tj.trim());}%></td>
          <td bgcolor="#CCCCCC" style= "cursor:pointer; "   onclick= "window.open( '<%=basePath %>luyun/fgd.jsp?bgd=<%=bgd %>&tdh=<%=tdh %>', '_blank')"><% if(xl!=null){out.print(xl.trim());}%></td>
        </tr>
<% 
//System.out.println("qqqqqqqqqq$$$$$$$qqqqqqqqqq");} catch (Exception ex) {
System.out.println("qqqqqqqqqqqqqqqqqqqqqqqqqqq"
+ ex.getMessage());
%>
<%
}
}
rs1.close();
stmt.close();
conn.close();

}
%>
        <tr>
          <td height="25" bgcolor="#CCCCCC">&nbsp;</td>
          <td bgcolor="#CCCCCC">&nbsp;</td>
          <td bgcolor="#CCCCCC">&nbsp;</td>
          <td bgcolor="#CCCCCC">&nbsp;</td>
          <td bgcolor="#CCCCCC">&nbsp;</td>
        </tr>      </table>
    <br>
    <br></td>  
  </tr>
</table>
</body>
</html>要在这个查询显示页面里加入应收金额(yingshoujine),币别[(bibie)币别分RMB/HKD/USD],汇率[(huilv)1/0.88/6.827],这3项在yingshou表中。
应付金额(yingfujine),币别(bibie),汇率(huilv),这3项在yingfu表中。毛利不在数据库中直接计算出来,
毛利=应收金额*汇率-应付金额*汇率。()
3个表共同的字段为tuoyun表的yewubaogaodanhao,yingshou表的baogaodanhao,yingfu表的baogaodanhao。
查询完毕后查询结果需要对其求和(比如选择09年5月-09年6月查询)那么5-6月的所有项咧出来后,对所显示的毛重、体积、箱量、应收金额、应付金额、毛利求和。谢谢,那位高手帮忙改下。

解决方案 »

  1.   

    说的有些乱啊,能不能用联合查询啊,如:
       select sum(A.毛重),sum(B.金额), from tuoyun as A join yingshou as B on(A.yewubaogaodanhao=B.baogaodanhao)
       where A.date > '2009-5-1' and A.date < '2009-6-30'
      

  2.   

    用这样的查询,即浪费代码,查询效率又低.建议使用存储过程,看看这里吧
    http://topic.csdn.net/u/20090708/15/9d9c00c9-4868-4eb5-83f3-7baa80bdf85c.html
      

  3.   

      用 List 存储数据,然后 for 循环迭代 ,相加 求和 。