【问题标题】:Arthmatic operation in sql query [closed]sql查询中的算术运算[关闭]
【发布时间】:2016-08-30 19:09:17
【问题描述】:

我在从数据库中获取数据时遇到问题。

我有一个名为purchaseorder 的表,我有一个数量列,使用它必须通过用户输入减去一些数量,并通过 jsp 页面显示结果,帮助我解决问题

下面是代码,

    String pno = request.getParameter("PONo");
    String receivedQty =request.getParameter("ReceivedQty");
    int Rqty = Integer.parseInt(receivedQty);
    /*String quantity = request.getParameter("Quantity");
    int Qty = Integer.parseInt(quantity);*/
    
    Connection conn = null;
    try {
        Class.forName("com.mysql.jdbc.Driver");
        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306", "root", "dinga");
        PreparedStatement ps = conn.prepareStatement("Select PODate,PONo,Quantity AS OrderingQty ,(Quantity-?) AS BalanceQty From project.purchaseorder where PONo=?");
        ps.setInt(1,Rqty );
        ps.setString(2,pno );
        
        ResultSet rs = ps.executeQuery();
        //System.out.println("resultset Value"+rs);
        if (rs.next()) {
            request.setAttribute("result", rs);
            rd = request.getRequestDispatcher("ProcessingActualGRN.jsp");
            rd.forward(request, response);
        }
    } catch (SQLException e) {
    } catch (ClassNotFoundException e) {
    } finally {
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException ex) {
        }
     }
    }
    }

jsp页面

    <table id="table2">
    <tr>
        <th>Iteam Discription</th>
        <th>OrderingQty</th>
        <th>PO Date</th>
        <th>Reveived Quantity</th>
        <th>Balance Quantity</th>
        <th>Received Date</th>
    </tr>
    <%
        do {
    %>  
    <tr>
        <td><%=request.getParameter("PONo") %></td>
        <td><%=rs.getInt(25)%></td>
        <td><%=request.getParameter("Quantity") %>
        <!-- <td>null(1)</td> -->
        <td><%=rs.getString(1) %></td>
        <td><%=request.getParameter("ReceivedQty")%></td>
        <td><%=request.getParameter("BalanceQty")%></td>
        <td><%=request.getParameter("ReceivedDate")%></td>
    </tr>
      <%
        } while (rs.next());
    %>`

在 jsp &lt;%=rs.getInt(25)%&gt; 我收到类似的错误

org.apache.jasper.JasperException: 在第 87 行处理 JSP 页面 /ProcessingActualGRN.jsp 时发生异常

87:

【问题讨论】:

  • @Honza Brabec,@Pillar,@Radiodef,@Lukas Eder
  • @ketan,TQ 解决方案是他们在代码中的任何错误
  • 将代码放入try catch block 并捕获异常。然后我们可以轻松地为您提供帮助
  • 我已经添加了 try catch 块
  • 好的@Santosh Vastrad。你遇到了什么异常?

标签: java jsp jdbc


【解决方案1】:
 <%
        do {
    %>  
    <tr>
        <td><%=request.getParameter("PONo") %></td>
        <td><%=rs.getString(1) %></td>
        <td><%=rs.getInt(3)%></td>
        <td><%=request.getParameter("ReceivedQty")%></td>
        <td><%=rs.getInt(4) %></td>
        <td><%=request.getParameter("ReceivedDate")%></td>
    </tr>
     <%
        } while (rs.next());
    %>  
  • 我得到了输出我在给出索引值时出错了...TQ

【讨论】:

    猜你喜欢
    • 2014-04-30
    • 1970-01-01
    • 2017-11-06
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多