Results 1 to 7 of 7
  1. #1
    kiran kumar is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Thumbs up How to delete the records

    Hi Everybody,

    i am facing some problem in java.please solve this problem.

    i have to button in my jsp. one is add and another one is delete.
    while adding the records i am add the those records into the arraylist that name is temp.

    Now i am not able to delete those records. how to do this.

    This is my code of my servlet program
    ------------------------------------------------------------

    temp=(ArrayList)session.getAttribute("repairvalues ");
    //This addLeaseId is checkbox name
    String param[]=req.getParameterValues("addLeaseId");


    if(param!=null)
    {
    for(int i=0;i<=param.length;i++)
    { int k = Integer.parseInt(param[i]);
    for(int j=0;j<=temp.size();j++)
    {
    if(k==j)
    {
    temp.remove(j);
    session.setAttribute("repairvalues", temp);


    }

    }

    }
    }
    I want to be delete the records what ever we selected those records want to be delete.

  2. #2
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    Default

    can you post a sample of the checkbox please. (the one in html code) or can you just describe me the content of the addLeastId.

    let me give you a idea on how i did it.
    in my JSP, i made java generates this HTML codes for me ^_^
    Imagine they are all in a Table.
    <input type="checkbox" name="check" value="0">. . .other data here
    <input type="checkbox" name="check" value="1">. . .other data here
    <input type="checkbox" name="check" value="2">. . .other data here
    <input type="checkbox" name="check" value="3">. . .other data here
    <input type="checkbox" name="check" value="4">. . .other data here
    <input type="checkbox" name="check" value="5">. . .other data here

    in my Servlet.
    String getCheckBox[] = new String[1000];
    getCheckBox = request.getParameterValues("check");

    now for example the user checks the CheckBox 0,1,4

    in my getCheckBox, it will contain this values.
    getCheckBox[0] ---> 0
    getCheckBox[1] ---> 1
    getCheckBox[2] ---> 4

    it will only get the values of the checked checkBox and i can now use these values and convert it to int types and use as a pointer in my arraylist. ^_^ it is a much simplier for me to do it that way.
    Mind only knows what lies near the heart, it alone sees the depth of the soul.

  3. #3
    kiran kumar is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default

    HI,
    First of all appriciate to you for giving the reply.What you saying is correct.some small changes in your code.I created the checkbox only one input tag. but this input tag is in for loop.So it is traveresing and print the how many we want. But i want to be delete the perticular record. Hoe to do this.Please give a code.Here addLeaseId is checkbox name.
    I am explaining to you clearly.What my question is. i have a one bean class and one ArrayList. After setting the bean values i added the bean object to ArrayList object that is temp.Now i want to be delete the what ever we selected the record in jsp.

  4. #4
    kiran kumar is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default

    what we selected records those records are to be deleted in temp. then only we are displaying other temp values

  5. #5
    Vijay Mishra is offline Member
    Join Date
    Nov 2008
    Posts
    5
    Rep Power
    0

    Default

    If you are clicking on delete record pass the same arraylist with values and iterate it and check the value to be removed which is I supoose coming in request.Then use Arraylist.remove method to remove the selected and show it back on the screen.
    If you still have the query let me know or you are not getting wht i am saying.

  6. #6
    kiran kumar is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default

    HI Vijay,

    Thank you for giving a reply. what you are saying i was tried with iterator also. but i didnot get.If you know the code.Please send the working code.

  7. #7
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Smile String[] directly from getParameterValues

    Java Code:
    String getCheckBox[] = request.getParameterValues("check");
    if((getCheckBox != null)&&(getCheckBox.length > 0)){processString(getCheckBox[index++]) while(index < getCheckBox.length);}
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Similar Threads

  1. Export records to Excel from MySQL
    By ansariazam in forum New To Java
    Replies: 3
    Last Post: 08-06-2008, 01:14 PM
  2. JList and records, what to do to solve the problem
    By willemjav in forum Java Applets
    Replies: 10
    Last Post: 06-11-2008, 02:28 PM
  3. Getting number of records (JDBC 2.0)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-11-2008, 08:51 AM
  4. Number of updated records
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-21-2008, 04:32 PM
  5. Query with 1 record vs. multiple records
    By anderma8 in forum JDBC
    Replies: 5
    Last Post: 07-09-2007, 11:33 PM

Posting Permissions

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