import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class DeleteProductServlet extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException, SQLException {
        PrintWriter out = response.getWriter();
        try {
            DBManager db=new DBManager();
           Connection conn=db.getConnection();
           Statement stmt=conn.createStatement();

           ResultSet rs=null;
           String id=request.getParameter("id");

            int result= stmt.executeUpdate("DELETE FROM TBL_PRODUCTS WHERE ID = id");//=+'"+id+"'+");
            //int result=stmt.executeUpdate(sql);

    out.println("Delete data sucessfully");
else if (result!=1)
    out.println("Delete data unsucessful");

        } finally {


Edited 6 Years Ago by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

Okay? What exception do you get? Have you printed the query to make sure you are executing what you think you are executing?

You are not committing the transaction and you are not closing either the statement or the connection.

Edit: And do not cobble together statements like that unless you want sporadic SQL syntax errors as well as innocent, as well as malicious, SQL injection attacks. Use a PreparedStatement.

Edited 6 Years Ago by masijade: n/a

This article has been dead for over six months. Start a new discussion instead.