aspose file tools*
The moose likes JDBC and the fly likes Data corruption in multi user web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Data corruption in multi user web application" Watch "Data corruption in multi user web application" New topic
Author

Data corruption in multi user web application

Jason Mrick
Greenhorn

Joined: Jun 22, 2010
Posts: 3
Hello. My company currently has a J2EE web app serving about 300 internal employees. Now that the app is being heavily used, we are noticing data corruption by the users. For example...

Step #:
1) User A is served a jsp which contains a form filled with data ready to be updated.
2) User B is served a jsp which contains a form filled with data ready to be updated. This is the same data as User A.
3) User A changes the data, and clicks "Update". The commit is done in Oracle.
4) User B, never seeing User A's change because the jsp was not refreshed, submits their changes (which are different from User A's). This overwrites User A's data with User B's and the first set of changes are lost.


Is there any Oracle/JDBC/Java best practices to resolve this? There must be something since web apps are so popular now....

TIA


Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Yeah, this is an old, and quite fundamental, problem with database backed applications (which predates web apps by some considerable time). Your application needs to implement a locking strategy of some sort. Have a google, or search these forums, for "optimistic locking".

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jason Mrick
Greenhorn

Joined: Jun 22, 2010
Posts: 3
Paul Sturrock wrote:Yeah, this is an old, and quite fundamental, problem with database backed applications (which predates web apps by some considerable time). Your application needs to implement a locking strategy of some sort. Have a google, or search these forums, for "optimistic locking".


Awsome! I will take a look! Thanks again.
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Or, depending on the frequency of this problem, you can check to see whether the data had been updated before you try to update it and respond with an error if this is the case. For example, you can add a lastUpdateDate (date/time) on the table you are updating. Read this along with the other data (but do not let the user update the field). When you update the data in the database, compare the lastUpdateDate with the one in your database and discontinue the update if they are unequal.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Tom Reilly wrote:Or, depending on the frequency of this problem, you can check to see whether the data had been updated before you try to update it and respond with an error if this is the case. For example, you can add a lastUpdateDate (date/time) on the table you are updating. Read this along with the other data (but do not let the user update the field). When you update the data in the database, compare the lastUpdateDate with the one in your database and discontinue the update if they are unequal.


No "or" about it - that's optimistic locking.
Jason Mrick
Greenhorn

Joined: Jun 22, 2010
Posts: 3
Tom Reilly wrote:Or, depending on the frequency of this problem, you can check to see whether the data had been updated before you try to update it and respond with an error if this is the case. For example, you can add a lastUpdateDate (date/time) on the table you are updating. Read this along with the other data (but do not let the user update the field). When you update the data in the database, compare the lastUpdateDate with the one in your database and discontinue the update if they are unequal.


Yeah, this was the approach we came up with so far but wanted to see what other options we had out there.....
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
No "or" about it - that's optimistic locking.
Excellent! Now I know what to call it without running out of breath :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Data corruption in multi user web application
 
Similar Threads
cewolf charts color
confused between attributes and parameters
Session duplicated
JMS related architecture question
Spring jQuery form submit request.getSession(false) returns session but with a new session id