0
import java.io.IOException;
import java.io.PrintWriter;
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 {
        response.setContentType("text/html;charset=UTF-8");
        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);

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

        } finally {
            out.close();
        }
    }



}

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

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by hiddenman91
0

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 by masijade: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.