PDA

View Full Version : Deleting records from the database using servlets and jsp


Cathy_Latte
08-07-2009, 01:58 AM
Hey guys I am trying to delete records from the database using servlets and jsp. I input the codes into the servlets however I do not know what to do at the jsp.

This is my servlets:
//Retreive the user data from the session object
User user = (User)request.getSession().getAttribute("USER_DATA");
Product product = (Product)request.getSession().getAttribute("PROD_DATA");

try {
//Ensure the the driver class is loaded.
Class.forName("com.mysql.jdbc.Driver");
//Create a connection to our database.
//localhost = server name
//myshop = database name
//root = user name, password = empty
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/feppz", "root", "");
//create an SQL statement, ? marks denote values that we will add later
PreparedStatement ps = con.prepareStatement("DELETE FROM products WHERE ProductId=?" );
//replace first ? mark with values from the feedbackText text box

ps.setString(8, request.getParameter("ProductId"));
ps.setString(1, request.getParameter("ProdName"));
ps.setString(2, request.getParameter("ProdColor"));
ps.setString(3, request.getParameter("ProdDesc"));
ps.setString(4, request.getParameter("UnitPrice"));
ps.setString(5, request.getParameter("Quantity"));
ps.setString(6, request.getParameter("ProdCatId"));
ps.setInt(7, user.getUserId());


//execute to insert into the database

ps.executeUpdate();
//close connection
con.close();
//redirect user to FeedbackSucceed.jsp page
response.sendRedirect("EditProductsAdminS(A).jsp");

} catch (Exception e) {
e.printStackTrace();
return;
}

}

}
And is it possible for me to delete my longblob images as well as the details associated with the products?

Thanks :D
Hope to hear from you soon!