posted 18 years ago
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();
}