在java中的单个类中执行多个查询

时间:2016-02-24 07:22:23

标签: java jdbc

当我要在课堂上执行2个查询时,我遇到了问题 只有第一个查询正在执行,帮我解决问题 我在下面尝试了一些编码

public class DamageCopyingData extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    String damageIssuePeriod = request.getParameter("DamageIssuePeriod");
    String damageTrNo = request.getParameter("DamageTrNo");
    int Dno = Integer.parseInt(damageTrNo);
    String returnNo = request.getParameter("ReturnNo");
    int Rno = Integer.parseInt(returnNo);
    String returnDate = request.getParameter("ReturnDate");
    String returnRef = request.getParameter("ReturnRef");

    String voucherNo = request.getParameter("VoucherNo");
    int vno = Integer.parseInt(voucherNo);
    try {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306", "root", "dinga");
        PreparedStatement ps = con.prepareStatement("INSERT INTO project.damagereturn(TransactionType,VoucherNo,VoucherDate,VoucherRef,Salesman,SalesRoute,Location,IssuetoCostCentre,Description,PrintCost,ProductNo,PackSize,CostPrice,DamageType,QtyPack,QtyPcs,Weight,ToWeight,TotalAmount,Total,ProductName,BatchNo,ExpiryDate,UOM,OnHandPacks,OnHandPieces) SELECT * FROM project.damagevoucher WHERE VoucherNo =?");

        ps.setInt(1, vno);
        int rs = ps.executeUpdate();
        System.out.println("value rs"+rs);
        System.out.println("success...1");

        if (rs==1) {

            PreparedStatement ps1 = con.prepareStatement("Update project.damagereturn(DamageIssuePeriod,DamageTrNo,ReturnNo,ReturnDate,ReturnRef) values(?,?,?,?,?)");
            ps1.setString(1, damageIssuePeriod);
            ps1.setInt(2, Dno);
            ps1.setInt(3, Rno);
            ps1.setString(4, returnDate);
            ps1.setString(5, returnRef);

            int rs1 = ps1.executeUpdate();
            System.out.println("value rs1"+rs1);
            System.out.println("success...2");
        }
    } catch (Exception e2) {
        e2.printStackTrace();
    }
}

}

  1. 第一个查询将从project.damagevoucher表中复制数据并粘贴到新表项目中.damagereturn
  2. 第二次会更新表格,添加一些细节,但该查询没有执行,请帮我解决问题

0 个答案:

没有答案