How to delete a specific entry in a GuestbookServlet


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: How to delete a specific entry in a GuestbookServlet

  1. #1
    Join Date
    May 2007
    Posts
    5

    How to delete a specific entry in a GuestbookServlet

    Hi,

    I'm setting up Guestbook and evrything is working fine except when Im trying to Delete an entry from the Guestbook. I'm using a servlet to delete the entry from the database only it deletes all entries. How do I specify the SQL statement so it only deletes a specific one?

    My SQL statment looks like this ;

    state.executeUpdate("Delete Name, Comment, Date from Guestbook");


    Any thoughts?

    /Robert

  2. #2
    Join Date
    Mar 2005
    Location
    UK, London
    Posts
    150
    Each record in your database needs to have a unique id. When u want to view, edit or delete a particalr record you use the unique id.

    Example

    ID Name LastName
    1 Jon Doe
    2 Jane Smith
    3 Patrik O'Niel

    To delete the second record (Jane Smith) you would use the unique id, which is 2, so your sql statment would look like this

    DELETE FROM GuestBook WHERE ID=2

    The above sql will delete any record in your table, which the field ID contains 2. As the ID field only contains unique numbers, only one record will be deleted and that is the record which matches the ID number to be deleted. You can also use the unique ID to edit a record is needed. Hope that answers your question.

  3. #3
    Join Date
    May 2007
    Posts
    5
    Hi again,

    I am using Access for my database andfor the ID in each table there is an autonumber which sets a number to each entry. The problem is that the database somehow remembers which numbers were removed and sets the number for a new entry in the table as one after the entry that was deleted.
    Example: I have 3 entries in my table which have ID nr 1-3, I then remove all of them and enter 3 new entries in the same table. Those entries have the ID nr 4-6, not 1-3 which they should have. I have to figure out a way for access to number my table correctly.

    Anyways thanx for the swift reply/
    Robert

  4. #4
    Join Date
    May 2007
    Posts
    3

    Reply

    u write query like
    state.executeUpdate("Delete Name, Comment, Date from Guestbook");
    it delete all row from table Guestbook .you should specify the condition
    in where clause which row u want to delete

Similar Threads

  1. help reg creating ms access file
    By vbcoder in forum VB Classic
    Replies: 9
    Last Post: 04-28-2005, 01:36 PM
  2. OVERSEAS Online Data Entry Information
    By jai in forum Careers
    Replies: 0
    Last Post: 02-21-2003, 12:43 AM
  3. data entry jobs
    By harish boddapati in forum Careers
    Replies: 2
    Last Post: 02-20-2003, 07:48 AM
  4. Replies: 2
    Last Post: 11-27-2000, 07:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center