This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transaction Control using CachedRowSet

 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();

}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic