To perform an insert operation using Prepared Statement
Assign values to input fields.
Execute the executeUpdate().
This example inserts employee records. The Prepared Statement looks like this:
Insert into DB_EMPLOYEE values (?, ?, ?, ?, ?) |
If you don’t want to insert values into all columns, your insert statement should look like this:
Insert into DB_EMPLOYEE (col1, col2) values (?, ?) public class jcdPsInsert { 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, otdDB2Connect.OtdDB2ConnectOTD otdDB2Connect_1, com.stc.connector.appconn.file. FileApplication FileClient_1, dtd.otdInputDTD_654315252.DBemployees otdInputDTD_DBemployees_1, dtd.otdOutputDTD1750519912.DBemployee otdOutputDTD_DBemployee_1 ) throws Throwable { FileClient_1.setText( "Inserting records into db_employee table using Prepared Statement....." ); FileClient_1.write(); otdInputDTD_DBemployees_1.unmarshalFromString( input.getText() ); for (int i1 = 0; i1 < otdInputDTD_DBemployees_1.countX_sequence_A(); i1 += 1) { otdDB2Connect_1.getInsert_ps().setEMP_NO( typeConverter.stringToShort( otdInputDTD_DBemployees_1.getX_sequence_A( i1 ).getEmpNo(), "#", false, 0 ) ); otdDB2Connect_1.getInsert_ps().setLAST_NAME( otdInputDTD_DBemployees_1. getX_sequence_A( i1 ).getLastname() ); otdDB2Connect_1.getInsert_ps().setFIRST_NAME( otdInputDTD_DBemployees_1. getX_sequence_A( i1 ).getFirstname() ); otdDB2Connect_1.getInsert_ps().setRATE( new java.math.BigDecimal( otdInputDTD_DBemployees_1.getX_sequence_A( i1 ).getRate() ) ); otdDB2Connect_1.getInsert_ps().setLAST_UPDATE( typeConverter. stringToSQLDate( otdInputDTD_DBemployees_1.getX_sequence_A( i1 ).getLastDate(), "yyyy-MM-dd hh:mm:ss", false, "" ) ); otdDB2Connect_1.getInsert_ps().executeUpdate(); } FileClient_1.setText( "Insert Done......" ); FileClient_1.write(); } } |