我试图将数据从另一个表(购物车)插入到表(order_details)中.当我执行此操作时,它在数据库中插入了两次数据.我不知道为什么会这样.有谁能够帮助我?提前致谢.
CartDAO
public boolean insertCart(String username)
{
try
{
sql = "INSERT INTO order_details (username, product_code, product_name, qty, product_price, product_pic, order_status)"
+"SELECT username, product_code, product_name, qty, product_price, product_pic, order_status FROM cart WHERE username = ? AND order_status = 1";
con = DbConnection.getConnection();
pst = con.prepareStatement(sql);
pst.setString(1, username);
pst.executeUpdate();
DbConnection.close();
return true;
}catch(ClassNotFoundException | SQLException ex)
{
Logger.getLogger(CartDAO.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
}
CartWS
public boolean insertOrderDetails(String username)
{
CartDAO dao = new CartDAO();
return dao.insertCart(username);
}