Using Database Operations

The Insert Operation

ProcedureTo Perform an Insert Operation on a Table

  1. Execute the insert() method. Assign a field.

  2. Insert the row by calling insertRow()

    This example inserts an employee record.


    package prjDB2_JCDjcdALL;
    
    
    public class jcdInsert
    {
    
        public com.stc.codegen.logger.Logger logger;
    
        public com.stc.codegen.alerter.Alerter alerter;
    
        public com.stc.codegen.util.CollaborationContext collabContext;
    
        public com.stc.codegen.util.TypeConverter typeConverter;
    
        public void receive( com.stc.connector.appconn.file.FileTextMessage 
    input, otdDB2.OtdDB2OTD otdDB2_1,     dtd.otdInputDTD_1206505729.
    DB_Employee otdInputDTD_DB_Employee_1, com.stc.connector.appconn.file.
    FileApplication FileClient_1 )
            throws Throwable
        {
            FileClient_1.setText( "Inserting records in to db_employee table......" );
            FileClient_1.write();
            otdInputDTD_DB_Employee_1.unmarshalFromString( input.getText() );
            otdDB2_1.getDb_employee().insert();
            for (int i1 = 0; i1 < otdInputDTD_DB_Employee_1.countX_sequence_A(); i1 += 1) {
                otdDB2_1.getDb_employee().setEMP_NO( typeConverter.stringToShort
    ( otdInputDTD_DB_Employee_1.getX_sequence_A( i1 ).getEmpNo(), "#", false, 0 ) );
                otdDB2_1.getDb_employee().setLAST_NAME( otdInputDTD_DB_Employee_1.
    getX_sequence_A( i1 ).getLastname() );
                otdDB2_1.getDb_employee().setFIRST_NAME( otdInputDTD_DB_Employee_1.
    getX_sequence_A( i1 ).getFirstname() );
                otdDB2_1.getDb_employee().setRATE( new java.math.BigDecimal
    ( otdInputDTD_DB_Employee_1.getX_sequence_A( i1 ).getRate() ) );
                otdDB2_1.getDb_employee().setLAST_UPDATE( typeConverter.stringToTimestamp
    ( otdInputDTD_DB_Employee_1.getX_sequence_A( i1 ).getLastDate(), "yyyy-MM-dd hh:mm:ss",
     false, "" ) );
                otdDB2_1.getDb_employee().insertRow();
            }
            FileClient_1.setText( "Insert Done." );
            FileClient_1.write();
        }
    
    }