您好我正在尝试执行查询,将数据从一个表复制到另一个表,即project.purchaseorder
到project.processingactualgrn
我试过的MySQL查询如下:
插入project.processingactualgrn (PONo,PODate,OrderingQty,ReceivedQty,BalanceQty)选择 PONO,PODate,Quantity AS OrderingQty,(Quantity-(Quantity-2))AS 来自project.purchaseorder的ReceivedQty,(Quantity-2)AS 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) {
}
}
}
}