...

View Full Version : Java Servlet to Delete record help PLz!



nabil1983
12-12-2007, 03:54 PM
Hiya

I've managed to access my database input records and search but im having huge problems trying to get a record to delete. Basically what i tried to do was copy and paste my code for creating a record and changing that about, but i have had no luck.

Can someone please help me all i want to do is to input a athlete name and then delete that record.

If neone can help i would really apreciate the help.

Peace.
NM




public static Result DeleteResult(String r, String a, String c, int s){
// Create a result.
// At the same time do database access to save the details
Result b = new Result(r, a, c, s);

try{
Statement st = dbcon.createStatement();
String cmd = "DELETE FROM resultsDB values ("
+ "'" + r + "' , '" + a + "' , '" + c + "' , " + s + ")";
System.out.println(cmd);
st.executeUpdate(cmd);
st.close();
} catch (Exception e) { e.printStackTrace(); }
return b;
}



import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;




public class DeleteResult extends HttpServlet {

public void init() throws ServletException{
super.init();
Result.initialize();
//System.out.println("Init - Servlet NewBook");
}

public void destroy(){
super.destroy();
Result.terminate();
//System.out.println("Destroy - Servlet NewBook");
}



public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println("<html>");
out.println("<head>");

String title = "Delete Result";





// String rr = request.getParameter("raceType");
String aa = request.getParameter("athlete");
String cc = request.getParameter("country");
int ss = (new Integer(request.getParameter("score"))).intValue();
Result b = Result.newResult(rr,aa,cc,ss);


out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
out.println("<h1>" + title + "</h1>");

out.println("<p>Result Deleted: ");
out.println(rr+ " "+ aa+ " "+ "(" + cc+") <italic>"+ ss+ "</italic>.");


out.println("<p>Back");
out.println("</body>");
out.println("</html>");
}
}

shyam
12-13-2007, 03:55 AM
public static Result DeleteResult(String r, String a, String c, int s){
// Create a result.
// At the same time do database access to save the details
Result b = new Result(r, a, c, s);

try{
Statement st = dbcon.createStatement();
String cmd = "DELETE FROM resultsDB values ("
+ "'" + r + "' , '" + a + "' , '" + c + "' , " + s + ")";
System.out.println(cmd);
st.executeUpdate(cmd);
st.close();
} catch (Exception e) { e.printStackTrace(); }
return b;
}

don't know which database ur using but afaik the delete query's syntax is wrong by most SQL standards take for instance MySQL
http://dev.mysql.com/doc/refman/5.0/en/delete.html

nabil1983
12-13-2007, 02:40 PM
Im using MS Access database. With fields : raceType, athlete, country and score.

Im using Tomcat to run the application.
i have tried many different ways but always end up back where i started, it seems that deleting a record is harder than i thought.
Ur MySQL page has different code than what im used to. The code i provided is code to insert a record, could you guide me into changing that code into deleting a record.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum