Solved

How can i synchronize table data?

Posted on 2011-03-25
9
360 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

813 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

19 Experts available now in Live!

Get 1:1 Help Now