aspose file tools*
The moose likes JDBC and the fly likes Transaction Control using CachedRowSet 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 "Transaction Control using CachedRowSet" Watch "Transaction Control using CachedRowSet" New topic
Author

Transaction Control using CachedRowSet

Sandeep Awasthi
Ranch Hand

Joined: Oct 23, 2003
Posts: 597
Hi All,

I am learning CachedRowSet. How do I control transation using CachedRowSet.

Suppose I have two CachedRowSets. I make changes to one of the CachedRowSet and do acceptChanges(); While making updates using another CachedRowSet, I get some database error. Now I want to rollback the changes which I made using first CachedRowSet. How do I do it?


I am using Oracle 9i Database.



I tried connection's rollback, but it doesnt work. Thanks in advance



Connection conn = null;

try {

Connection conn = DriverManager.getConnection(..);

conn.setAutoCommit(false);
Statement s = conn.createStatement();
ResultSet rs1 = conn.executeQuery(..);
ResultSet rs2 = conn.executeQuery("Some other query");
CachedRowSet cs1 = new CachedRowSetImpl();
CachedRowSet cs2 = new CachedRowSetImpl();
cs1.populate(rs1);
cs2.populate(rs2);


cs1.absolute(2);

cs1.updateString(2,"SomeValue");
cs1.updateRow();
cs1.acceptChanges(conn);

//Successful

cs2.absolute(3);

cs2.updateString(3,"SomeOtherValue");
cs2.updateRow();
cs2.acceptChanges(conn);

//Some error

conn.commit();

}
catch(Exception e)
{
conn.rollback();

}


Sandeep
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Transaction Control using CachedRowSet