• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Update Database with the better way

 
naro pad
Ranch Hand
Posts: 58
Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a form where I read data from database and fill some text fields. Now the user can make changes on them and save them.

Now what mechanism I have think about to update the tables is to save them temporary into objects and when the form is submit to check the object with the right getParameter to see if they differ and update the table.

Is there any better way. For example using AJAX or anything else?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33700
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Panayiotis,
What you described is the basic outline. You would need to do the compare regardless of whether you use AJAX.
 
Xinsheng Chen
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can check whether the content is changed or not on the client side using JavaScipt. On the cursor moving away or the "Submit" button being pressed, you use JavaScript code to check whether the content is changed or not. You set a "changed" hidden input value to true or false accordingly. On your server side, you first get the value of "changed" and check it -- If the content is not changed, you avoid a trip to the the database.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64204
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Xinsheng Chen:
You can check whether the content is changed or not on the client side using JavaScipt.

Sorry, but that is not a very good idea. You can never trust what the client sends (it can easily be spoofed) and you cannot control whether the user might turn JavaScript on or not.

All important business logic must take place on the server.
 
naro pad
Ranch Hand
Posts: 58
Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks a lot for the replies...
I will see what I will do
 
Prasad Tamirisa
Ranch Hand
Posts: 130
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All important business logic must take place on the server.

I Agree. Doing this type of validation on the client side is always unsafe. Instead,

1) you can store them in to a bean/form.
2) Write a logic to connect to the database and update the values in a DAO.
3) Use/Call this DAO from the corresponding servlet.
[ May 28, 2008: Message edited by: Prasad Tamirisa ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic