ManiVasagam_1 0 Newbie Poster

I am trying to edit and delete a single record from multiple records.Here below is my sample record displaying on jsp page,

I can edit the record for each row easily using below code,

  <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
         <%@ page import="java.util.List" %>
          <%@ page import="java.util.Iterator" %>

     <%@page import="java.sql.ResultSet"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script src="jquery1.11.0.min.js"></script>

    </head>
    <body>

        <script type="text/javascript">


                function editRecording(task_id) {
                    //alert(task_id)

                            url = "EditRecord";
                            window.location="/RTTSchecking/"+url+"?task_id="+task_id;

                    }


        </script>

  <table align="center" border="1px" width="80%"  >
    <thead>
        <tr>
        <th>User_Id</th>
        <th>Class</th>
        <th>Subject</th>
        <th>Chapter</th>
        <th>Planned_Features</th>
        <th>Planned_Date</th>

    </thead>


            <%Iterator itr;%>        
            <%List data = (List) request.getAttribute("TaskData");

            for(itr = data.iterator(); itr.hasNext();)
            {
                %>
                <tr>
                <% String s = (String) itr.next(); 
                %>
                <td style="background-color: yellow;">
                <input type="text" name="tid" value="<%=s %>"></td>
                <td><input type="text" name="tid" value="<%=itr.next() %>"></td>

                <td><%=itr.next() %></td>
                <td><%=itr.next() %></td>
                <td><%=itr.next() %></td>
                <td><%=itr.next() %></td>


                <td><input type="button"  value="edit" name="<%=s%>" onclick="editRecording(this.name);"></td> 
             <td><input type="button"  value="delete" name="<%=s%>" onclick="deleteRecording(this.name);"></td> 



                <% } %>



                </tr>

                </table>


    </body>
    </html>

EditREcord(servlet):

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PrintWriter out = response.getWriter();

        try {

            String a=request.getParameter("task_id");

        convty = new Connectivity();
        con = convty.setConnection();
        st = con.createStatement();
        query = "select * from task_table where task_id='"+a+"'";
        rset = convty.getResultSet(query, con);


        }
        catch(Exception e) {

        }
        finally {
            request.setAttribute("EditData", rset);
            RequestDispatcher dd= request.getRequestDispatcher("editdata.jsp");
            dd.forward(request, response);
            out.close();
            //out.println(""+tid);
        }

    }

Above code working fine.But my problem is, i want to delete record based on User_id, Class, Subject, Chapter and Planned_Date so how can i get these values from single row (which want to delete row)?

how to achive this below code?,

  <script type="text/javascript">


                        function deleteRecording(User_id,Class,Subject,Chapter,Date) {
                            //alert(task_id,Class,Subject,Chapter,Date)

                                    url = "EditRecord";
                                    window.location="/RTTSchecking/"+url+"?user_id="+User_id+"&Tclass="+Class+"&subject="+Subject+"&chapter="+Chapter+"&date="+Date;

                </script>

once if i achieved above code then i can easily delete selected single record from multiple rows using below code,

try {

                String uid=request.getParameter("user_id");
String class=request.getParameter("Tclass");
String sub=request.getParameter("subject");
String chap=request.getParameter("chapter");
String date=request.getParameter("date");

            convty = new Connectivity();
            con = convty.setConnection();
            st = con.createStatement();
            query = "delete from task_table where User_id='"+uid+"' and class='"+class+"' and subject='"+sub+"' and chapter='"+chap+"' and date='"+date+"'";
           st.executeUpdate(query);


            }
            catch(Exception e) {

            }

Note : I can do delete records using delete from task_table where User_id='"+uid+"';

but how to do with query = "delete from task_table where User_id='"+uid+"' and class='"+class+"' and subject='"+sub+"' and chapter='"+chap+"' and date='"+date+"'";

I hope someone will help me out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.