Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Java Servlet to Delete record help PLz!

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

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by nabil1983 View Post
    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;
        }
    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
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    re

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •