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
CODE
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;
}
// 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;
}
CODE
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>");
}
}