File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transaction Control using CachedRowSet

 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • 0
  • 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();

}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic