我的桌子一代变坏了

时间:2014-03-03 15:22:50

标签: java sql jsp servlets

最近我创建了一个表来显示我的数据库中的所有信息,但它不会那么顺利。

这是我的代码

reveneuPage.jsp

<table class="table table-bordered table-striped table-hover">
                        <thead>
                        <th> Date </th>
                        <c:forEach var="revcodes" items="${revcodeList}">
                        <th>${revcodes.revcode}</th>
                        </c:forEach>
                        <!--<th> Total </th>-->
                        </thead>

                          <c:forEach var="revcodedate" items="${revcodeList}">
                        <tr>
                            <td>${revcodedate.date}</td>
                            <c:forEach var="revcodeAmount" items="${revcodeList}">
                                <td>${revcodeAmount.amount}</td>
                            </c:forEach>



                        </tr>
                        </c:forEach>
                    </table>

revenuereport.java

String year = request.getParameter("year");
            String month = request.getParameter("month");
            a = new Db();
            String query = "SELECT\n" +
                            "  user_payment.revcode,\n" +
                            "  user_payment.date,\n" +
                            "  user_payment.amount,\n" +
                            "   revcode.revcodeactual\n" +
                            "FROM\n" +
                            "  user_payment, revcode\n" +
                            "WHERE\n" +
                            "  YEAR(user_payment.date) = '"+year+"' AND MONTH(user_payment.date) = '"+month+"' \n" +
                            "   and user_payment.revcode = revcode.revcodeactual\n" +
                            "Group By \n" +
                            "  user_payment.revcode, date\n" +
                            "Order By\n" +
                            "  user_payment.date ASC";

            resultSet = a.sqlQuery(query);
            while(resultSet.next()){
                revcodeList.add(new revcodes(
                        resultSet.getInt("revcodeactual"),
                        resultSet.getDate("date"),
                        resultSet.getDouble("amount")
                        ));

            }

            request.setAttribute("revcodeList", revcodeList);
            RequestDispatcher rd = request.getRequestDispatcher("revenuePage.jsp");
            rd.forward(request, response);

并且在执行此代码之后,我获得了相同日期的25行的重复版n个代码。 我该怎么办?我的查询错误地构造了吗?或者我误用了传递servlet响应和请求的对象?

我上传了我的屏幕截图here

0 个答案:

没有答案