Batch implementation of CallableStatement in java

Below is the code which demonstrates the implementation of batch update of CallableStatement  in java

import oracle.jdbc.*;
import oracle.jdbc.pool.OracleDataSource;
import oracle.jdbc.OracleDriver;

  try
        {
String sql = "{call PKGNAME.PROCNAME(?,?,?)}";
             stmt = con.prepareCall(sql);

 for(int index = 0; index < list.size(); index++)
            {
                obj = (BankUploadBean)list.get(index);
                   stmt.setInt(1, ID);
                   stmt.setString(2, NAME);
                   stmt.setString(3, user);
                  
                   stmt.addBatch();
                  
              
           
            }//for
            stmt.executeBatch();
          
           //System.out.println("noOfRowsAffected"+noOfRowsAffected.length);
            stmt.clearBatch();
            stmt.close();
            stmt=null;


 }
        catch(Exception e)
        {           //
           
            try{
                con.rollback();
                 return_flag ="0";
            }
            catch(Exception ex)
            {
                //
            }
           
           
          }
        finally
        {
            try
            {
                con.commit();
                if(con!=null)
                {
                 con.close();
                }
                obj=null;
               
            }
            catch(Exception e)
            {
                return_flag ="0";
                //
            }
          
        }
        return return_flag;
    }

No comments:

Post a Comment