Solved

How can i synchronize table data?

Posted on 2011-03-25
9
358 Views
Last Modified: 2012-05-11
Dear Experts,

I have a table called EMPLOYEE, suppose if two employees are trying to update the same filed data in that table. how can i avoid this?  
0
Comment
Question by:haneef_nb
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 17

Expert Comment

by:Dejan Pažin
ID: 35215267
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35215322
Is this a Java q or an Oracle one?
0
 
LVL 17

Accepted Solution

by:
Dejan Pažin earned 500 total points
ID: 35215361

If for example you are using Hibernate, you can have optimistic locking auto implemented for you by version attribute on the entity:

Each time before a change is submited to the database the version attribute is checked and if it is not the in the database as on the entity, then someone has changed the content and the transaction will not be commited. You will have to read the entity again and then save it (and the sam procedure will occure). Once the change is approved, the version attribute is increased.

0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35217493
@ CEHJ

Say correct you can do it in 2 ways !!

in oracle auto commit off then commit while your finish your job !!

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35217677
From an Oracle (or just about any RDBMS), you really don't need to worry about this. The first update will lock the row will get it. The second update will block until the lock is released.

You may have an application issue that you need to work out if two people update the same field about the same time, the 'locked' update is not aware of the previous commit. It might generate some bad data. ÿ 

You will need to control that at the application layer.
For example:
user1: update emp set salary=salary*10 where emp_id=1;
user2: update emp set salary=salary*10 where emp_id=1;
user1: commit;
user2: commit;

What is the 'new' salary for employee?
0
 

Author Comment

by:haneef_nb
ID: 35224560
Dear Experts,

i want in both ways, in Oracle & Java..

Please explain in brief in both the ways..
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35224565
There is no 'both' ways.  There is how the RDBMS handles row locking then how a the app makes the calls.

Oracle is the RDBMS and Java is the app layer making calls to the RDBMS.  They really aren't the same.
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35224859
in oracle auto commit off then commit while your finish your job !!
0
 

Author Closing Comment

by:haneef_nb
ID: 35376531
Thanks..
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This video shows how to recover a database from a user managed backup
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now