-3
我在從數據庫中獲取數據時遇到問題。sql查詢中的關節手術
我有表名爲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中<%=rs.getInt(25)%>
我收到錯誤等
org.apache.jasper.JasperException:發生異常處理JSP頁/ProcessingActualGRN.jsp在線路87
87:<%= rs.getInt(25)%>
@Honza Brabec,@ Pillar,@ Radiodef,@ Lukas Eder –
@ ketan,TQ和什麼是解決方案是他們在代碼 –
代碼中的任何錯誤,把代碼放在try catch塊中並捕獲異常。然後我們可以很輕鬆地幫你 – androidGenX