Sun Java Solaris Communities My SDN Account Join SDN
 
Tutorials & Code Camps

jGuru: Help: Using Transactions

 


[Exercise | API Docs | Short Course| Exercises]

Help is available for each task.



    Task 1

    To enable transaction handling, in doUpdate(), add code to turn off autocommit.

          con.setAutoCommit( false );
    

    Task 2

    In doUpdate(), if the number of rows affected is zero,

    • Print a message to System.err that the previous operations will be rolled back.
    • Set the rows processed total iProcessedCount to zero.
    • Set the error flag bError to true and exit the processing loop.
              System.err.println( "Note: EUTrans will " +
                "rollback ALL Statements for " + 
                 sargRBName + " if any Statement, " + 
                "including DDL, returns a zero count.\n"
                                );
              iProcessedCount = 0;
              bError = true;
              break;
    

    Task 3

    In doUpdate(), in the last two catch blocks, add code to set the rows processed total iProcessedCount to zero and set the error flag bError to true.

          iProcessedCount = 0;
          bError = true;
    

    Task 4

    In doUpdate(), in the finally block, check the error flag bError. If it is true, issue a rollback and print a message. If false, commit the statements.

            if( bError ) 
            {
              con.rollback();
              System.err.println( "ALL Statements for " + 
                 sargRBName + " were rolled back.\n" );
            }
            else { con.commit(); }
    

Copyright 1996-2000 jGuru.com. All Rights Reserved.