aspose file tools*
The moose likes JDBC and the fly likes How to do transaction management? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to do transaction management?" Watch "How to do transaction management?" New topic
Author

How to do transaction management?

bilal haider
Ranch Hand

Joined: Feb 08, 2011
Posts: 47

I have a database table that logs the changes in other table. table structure is as following.
Log_Table(id, table_name, operation, flag)
values(1,Customer,1,1);
values(2,Customer,2,1);
values(3,Customer,1,1);
values(4,Customer,2,1);
values(5,Customer,1,1);

I update this table against a button on a web page. by doing following operations.

public List<Long> select_Changes()
{
1) select id from Log_Table where flag =1;
}
public void update_table(List<Long> ids)
{

2)update Log_Table set flag =0 where id in( ids)
}

Problem is that between first and second operation its up to the user to perform the operation. Meanwhile another user at same time does the same operations. now i want that for this user already selected rows for first user should not be selected by the second user. e.g second user when do the first operation should get

values(6,Customer,2,1);
values(7,Customer,1,1);

Please suggest what should i do? I need to lock the rows for any kind of operation after rows are get selected. I tried select for update clause but it did not solve the problem. Its in a web application.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30752
    
156

You are correct that you need to setup a transaction. See the "Using Transactions to Preserve Data Integrity" section of Oracle's transaction page for how to use transactions with raw JDBC. From a code point of you, you'll need to set the transaction isolation level.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to do transaction management?