| Refresh | Home EGTry.com

call multiple store procedures in one transitional execution


package dbtest;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.util.Date;
import java.sql.ResultSet;
import java.sql.Statement;

public class MultipleMacroCall {

	/*
	 * 
REPLACE MACRO teradata1.GoalDetail_Ins  (
 mySourceSystemId      CHAR(2)
,myTopAirlineCd        CHAR(2)              
,mySubCd               CHAR(2)   
              
,myGoalQuadrantCd      CHAR(2)            
,myGoalTypeCd               CHAR(2)     
,myGoalTrackingPeriod            CHAR(1)

,myTrackStartDate                DATE
,myTrackEndDate                  DATE
,myGoalValue                     DECIMAL(18,6)

,myActiveInd                     CHAR(1)
,myEffectiveDate                 DATE
,myDiscontinueDate               DATE

) AS  (  

INSERT INTO	aed_db.GoalDetail
( 
 SourceSystemId                
,TopAirlineCd                  
,SubCd                         
,GoalQuadrantCd                
,GoalTypeCd                    
,GoalTrackingPeriod            
,TrackStartDate                
,TrackEndDate                  
,GoalValue                     
,ActiveInd                     
,EffectiveDate                 
,DiscontinueDate               
,TdwLoadDate                   
,TdwLoadTime                   

) 
SELECT	 
 :mySourceSystemId     
,:myTopAirlineCd       
,:mySubCd              
,:myGoalQuadrantCd     
,:myGoalTypeCd         
,:myGoalTrackingPeriod 
,:myTrackStartDate     
,:myTrackEndDate       
,:myGoalValue          
,:myActiveInd          
,:myEffectiveDate      
,:myDiscontinueDate    
,DATE
,CURRENT_TIMESTAMP	;);
	 */
	public static void main(String[] args) throws Exception {
		
		Connection conn=DbUtil.getConnection();

		
		CallableStatement st=null;
		try
		{
			System.out.println("start at: "+new Date());	
			
			st=conn.prepareCall("execute aed_db.GoalDetail_ins(?,?,?,  ?,?,?,  ?,?,?,  ?,?,?);");
			
			for(int i=0; i<1100; i++) {

			st.setString(1, "ZA"); //SourceSystemId
			st.setString(2, "ZA"); //TopAirlineCd
			st.setString(3, "01"); //SubCd
			
			st.setString(4, "RV");
			st.setString(5, "02");
			st.setString(6, "D");
			
			java.util.Date today=new java.util.Date();
			java.sql.Date sqlDate=new java.sql.Date(today.getTime());
			st.setDate(7, sqlDate);
			st.setDate(8, sqlDate);
			st.setDouble(9,3456.1D);
			
			st.setString(10, "Y");
			st.setDate(11, sqlDate);
			st.setDate(12, sqlDate);
			st.addBatch();
			
			}
			
			st.executeBatch();
			System.out.println("Done at: "+new Date());
			
			/*
			int c=st.executeUpdate("Insert Into teradata1.GoalDetail (SourceSystemId, TopAirlineCd, SubCd, GoalQuadrantCd, GoalTypeCd, GoalTrackingPeriod,TrackStartDate, TrackEndDate, GoalValue) values "
					+"('ZA', 'ZA', '01', 'RV', '02', 'D', '2011-01-01', '2011-01-01',100)");
			System.out.println(c+" rows has been inserted");
			*/
		}
		catch (Exception e) {
			e.printStackTrace(System.out);
		}
		finally {
			if(st!=null) st.close();
		}
		
	}

}