Failed to update mysql data using servlet. no error was reported, but update FAILED ~ Please kindly advise

Source: Internet
Author: User
This is an updated function. in the productdaoimpl class: publicintupdateProduct (Productproduct) {intflag0; DBConnectconnnull; PreparedStatementpstmtnull; updatestatementStringsql & quot; updateproductinfosetproductnumber ?, Productvalue? Whereproductname? Mysqlservlet

This is an updated function. in the productdaoimpl class:
Public int updateProduct (Product product ){
Int flag = 0;
DBConnect conn = null;
PreparedStatement pstmt = null;

//update statement    String sql = "update productinfo set productnumber=?,productvalue=?  where productname=?";    try {//connect DB    conn = new DBConnect() ;    pstmt = conn.getConnection().prepareStatement(sql) ;    pstmt.setString(1, product.getProductnumber());    pstmt.setString(2, product.getProductvalue());    pstmt.setString(3, product.getProductname());//update    pstmt.executeUpdate();    flag = 1;    pstmt.close();    } catch (Exception e) {    e.printStackTrace();    } finally {    conn.close();    }    return flag;

}

UpdateServlet code:
Package jspservlet. servlet;

Import java. io. IOException;

Import javax. servlet. ServletException;
Import javax. servlet. http. HttpServlet;
Import javax. servlet. http. HttpServletRequest;
Import javax. servlet. http. HttpServletResponse;
Import javax. servlet. http. HttpSession;

Import jspservlet. dao. ProductDAO;
Import jspservlet. dao. impl. ProductDAOImpl;
Import jspservlet. vo. Product;

Public class ProductUpdateServlet extends HttpServlet {

Public void doGet (HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {this. doPost (req, res);} public void doPost (HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {Product product = new Product (); product. setProductname (req. getParameter ("productname"); ProductDAO dao = new ProductDAOImpl (); int flag = 0; int flag2 = 1; try {fla G2 = dao. queryByProductName (product);} catch (Exception e) {// TODO Auto-generated catch block e. printStackTrace ();} if (flag2 = 1) {res. sendRedirect (". /errorRegister. jsp ");} else {try {flag = dao. updateProduct (product);} catch (Exception e) {// TODO Auto-generated catch block e. printStackTrace ();} if (flag = 1) {// What Is session? HttpSession session = req. getSession (); session. setAttribute ("productname", product. getProductname (); res. sendRedirect (". /success. jsp ");} else {res. sendRedirect (". /error. jsp ");}}}

}

JSP page:

<% @ Page language = "java" pageEncoding = "GB18030" %>



Delete Product





The name of the product you want to update:

    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.