Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Update and Delete database in jsp  RSS feed

 
zeb usman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I m creating a small application using jsp and servlet. There is a form (index.jsp)having 10 fields on
submitting the form all the values are added into database.There is a page that show retieve items from database and there are 2 extra columns(10+2) for "DELETE" AND "UPDATE" On clicking delete which
is hyperlink that particular row should
be deleted and on clicking update ,i should be able to update its value. So anyone will tell me how to give Delete and Update (by id Auto incremented in Database)???
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you adding the values in the database? Do the same for Delete and Update too. Create a separate SQL statement object for delete and update and execute it. What exactly is it that you are stuck with? And welcome to the ranch Usman. :)
 
zeb usman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You! Mansukhdeep Thind
Iam Inserting Data into database by MVC pattern.
Then i have created a jsp page (delete.jsp) in which iam executing a delete statement
Delete * from Manager where id= ??
Foto025.jpg
[Thumbnail for Foto025.jpg]
hyperlink
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Delete * from Manager where id= ??


The right hand side has to be the identity of the row that you selected for deletion / update:

a) You need to identify which row you have clicked first.

b) Then validate its value(maybe name or something unique to a row) against its value in the table in the database.

c) If it matches, then go ahead and delete / update it.
 
zeb usman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One Last Question.
Bro How to identify which row user clicked to delete ??
Please give a short example.
Thank You!
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:a) You need to identify which row you have clicked first.

b) Then validate its value(maybe name or something unique to a row) against its value in the table in the database.

It is a bad idea to tie the logic to the row number. It is further bad to map the row value in the database.
A simple implementation would have the ID as a parameter for the link.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit Ghorpade wrote:
Mansukhdeep Thind wrote:a) You need to identify which row you have clicked first.

b) Then validate its value(maybe name or something unique to a row) against its value in the table in the database.

It is a bad idea to tie the logic to the row number. It is further bad to map the row value in the database.


Why is that Amit?

Amit Ghorpade wrote:
A simple implementation would have the ID as a parameter for the link.


What do you mean by setting ID as parameter for the link?
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:Why is that Amit?

There is something known as coupling.

Mansukhdeep Thind wrote:
What do you mean by setting ID as parameter for the link?

I thought the sentence was self explanatory. Well here is more verbose.
The ID that needs to be manipulated should be appended as a request parameter to the link.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit Ghorpade wrote:A simple implementation would have the ID as a parameter for the link.

I don't think that's such a good idea, either. For starters, DB IDs (assuming that's what we're talking about here) should never be exposed to users. Secondly, URL parameters end up in all kinds of places where you don't want them to end up (caches, access logs, browser history etc.). Lastly, URL parameters are susceptible to fiddling. This should be a POST form submit with an encrypted parameter (possibly the ID) that indicates what to delete.
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:I don't think that's such a good idea, either.

Agreed. That is why I said simplest way of doing it was passing the ID. Here I made the assumption that the ID is displayed on the page.
It is actually based on the requirement how much complexity can be added. But yes a secure and robust implementation would be more like what you said.
 
zeb usman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to Pass Id ?
Please Provide small Demo ??
Thank
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!