-
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
-
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.
-
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
-
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
-
By vbcoder in forum VB Classic
Replies: 9
Last Post: 04-28-2005, 12:36 PM
-
Replies: 0
Last Post: 02-20-2003, 11:43 PM
-
By harish boddapati in forum Careers
Replies: 2
Last Post: 02-20-2003, 06:48 AM
-
By koshy in forum ASP.NET
Replies: 2
Last Post: 11-27-2000, 06: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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks