您好,我正在尝试执行查询,以便将数据从一个表复制到另一个表,这是 project.purchaseorder
至 project.processingactualgrn
我尝试的mysql查询如下:
插入project.processingactualgrn(pono,podate,orderingqty,receivedqty,balanceqty)选择pono,podate,quantity作为orderingqty,(quantity-(quantity-2))作为receivedqty,(quantity-2)作为来自project.purchaseorder的balanceqty,其中pono=1212;
在上面的查询中,我使用了值
在程序中,我使用占位符,使用preparedstatement执行查询用户输入的值 ex-(Quantity-2) AS BalanceQty in this '2'
必须存储在数据库中
protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
RequestDispatcher rd = null;
String pno = request.getParameter("PONo");
int p = Integer.parseInt(pno);
String receivedQty1 =request.getParameter("ReceivedQty1");
int Rqty1= Integer.parseInt(receivedQty1);
String receivedQty2 =request.getParameter("ReceivedQty2");
int Rqty2= Integer.parseInt(receivedQty2);
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306", "root", "dinga");
PreparedStatement ps = conn.prepareStatement("Insert into project.processingactualgrn (PODate,PONo,OrderingQty,ReceivedQty,BalanceQty) Select PODate,PONo,Quantity AS OrderingQty,(Quantity-(Quantity-?) )AS ReceivedQty,(Quantity-?) AS BalanceQty from project.purchaseorder where PONo=?");
ps.setInt(1,Rqty1);
ps.setInt(2,Rqty2);
ps.setInt(3,p);
System.out.println("value of ps"+ps);
int rs = ps.executeUpdate();
System.out.println("value of ps"+ps);
if(rs!=0){
rd = request.getRequestDispatcher("view/sucess.html");
rd.forward(request, response);
}
} catch (SQLException e) {
} catch (ClassNotFoundException e) {
} finally {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException ex) {
}
}
}
}
暂无答案!
目前还没有任何答案,快来回答吧!