A table OTD represents a database table. It consists of fields and methods. Fields correspond to the columns of a table while methods are the operations that you can apply to the OTD. This allows you to perform Query, Update, Insert, and Delete SQL operations in a table. The ability to update via a ResultSet is called “Updatable ResultSet”, which is a feature supported by this adapter.
By default, the Table OTD has UpdatableConcurrency and ScrollTypeForwardOnly. Normally you do not have to change the default setting.
The type of result returned by the select() method can be specified using:
SetConcurrencytoUpdatable
SetConcurrencytoReadOnly
SetScrollTypetoForwardOnly
SetScrollTypetoScrollSensitive
SetScrollTypetoInsensitive
Execute the select() method with the “where” clause specified if necessary.
Loop through the ResultSet using the next() method.
Process the return record within a while() loop.
For example:
package prjJDBC_JCDjcdALL; public class jcdTableSelect { 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, dtd.otdInputDTD_1394195520.DBemployees otdInputDTD_DBemployees_1, otdJDBC.OtdJDBCOTD otdJDBC_1, dtd.otdOutputDTD882991309.DBemployee otdOutputDTD_DBemployee_1, com.stc.connector.appconn.file.FileApplication FileClient_1 ) throws Throwable { FileClient_1.setText( "Selecting record(s) from db_employee table via table select .." ); FileClient_1.write(); otdJDBC_1.getDB_EMPLOYEE().select( input.getText() ); while (otdJDBC_1.getDB_EMPLOYEE().next()) { otdOutputDTD_DBemployee_1.setEmpNo( typeConverter.shortToString( otdJDBC_1.getDB_EMPLOYEE().getEMP_NO(), "#", false, "" ) ); otdOutputDTD_DBemployee_1.setLastname( otdJDBC_1.getDB_EMPLOYEE().getLAST_NAME() ); otdOutputDTD_DBemployee_1.setFirstname( otdJDBC_1.getDB_EMPLOYEE().getFIRST_NAME() ); otdOutputDTD_DBemployee_1.setRate( otdJDBC_1.getDB_EMPLOYEE().getRATE().toString() ); otdOutputDTD_DBemployee_1.setLastDate( typeConverter.dateToString( otdJDBC_1.getDB_EMPLOYEE().getLAST_UPDATE(), "yyyy-MM-dd hh:mm:ss", false, "" ) ); FileClient_1.setText( otdOutputDTD_DBemployee_1.marshalToString() ); FileClient_1.write(); } FileClient_1.setText( "Done table select." ); FileClient_1.write(); } } |
Execute the insert() method. Assign a value to a field.
Insert the row by calling insertRow()
This example inserts an employee record.
package prjJDBC_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, com.stc.connector.appconn.file.FileApplication FileClient_1, dtd.otdInputDTD_1394195520.DBemployees otdInputDTD_DBemployees_1, dtd.otdOutputDTD882991309.DBemployee otdOutputDTD_DBemployee_1, otdJDBC.OtdJDBCOTD otdJDBC_1 ) throws Throwable { FileClient_1.setText( "Inserting records into db_employee table .." ); FileClient_1.write(); otdInputDTD_DBemployees_1.unmarshalFromString( input.getText() ); for (int i1 = 0; i1 < otdInputDTD_DBemployees_1.countX_sequence_A(); i1 += 1) { otdJDBC_1.getInsert_Ps().setEmp_no( typeConverter.stringToShort( otdInputDTD_DBemployees_1.getX_sequence_A( i1 ).getEmpNo(), "#", false, 0 ) ); otdJDBC_1.getInsert_Ps().setLast_name( otdInputDTD_DBemployees_1.getX_sequence_A( i1 ).getLastname() ); otdJDBC_1.getInsert_Ps().setFirst_name( otdInputDTD_DBemployees_1.getX_sequence_A( i1 ).getFirstname() ); otdJDBC_1.getInsert_Ps().setRate( new java.math.BigDecimal( otdInputDTD_DBemployees_1.getX_sequence_A( i1 ). getRate() ) ); otdJDBC_1.getInsert_Ps().setLast_update( typeConverter.stringToSQLDate( otdInputDTD_DBemployees_1. getX_sequence_A( i1 ).getLastDate(), "yyyy-MM-dd hh:mm:ss", false, "" ) ); otdJDBC_1.getInsert_Ps().executeUpdate(); } FileClient_1.setText( "Done Insert." ); FileClient_1.write(); } } |
Execute the update() method.
Using a while loop together with next(), move to the row that you want to update.
Assign updating value(s) to the fields of the table OTD
Update the row by calling updateRow().
package prjJDBC_JCDjcdALL; public class jcdUpdate { 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, otdJDBC.OtdJDBCOTD otdJDBC_1, dtd.otdOutputDTD882991309.DBemployee otdOutputDTD_DBemployee_1, dtd.otdInputDTD_1394195520.DBemployees otdInputDTD_DBemployees_1, com.stc.connector.appconn.file.FileApplication FileClient_1 ) throws Throwable { FileClient_1.setText( "Update the Rate and Last_update fields using Prepared Statement.. " ); FileClient_1.write(); otdJDBC_1.getUpdate_Ps().setEmp_no( typeConverter.stringToShort( input.getText(), "#", false, 0 ) ); otdJDBC_1.getUpdate_Ps().executeUpdate(); FileClient_1.setText( "Done Update." ); FileClient_1.write(); } } |
Execute the delete() method.
In this example DELETE an employee.
package prjJDBC_JCDjcdALL; public class jcdDelete { 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, dtd.otdInputDTD_1394195520.DBemployees otdInputDTD_DBemployees_1, otdJDBC.OtdJDBCOTD otdJDBC_1, dtd.otdOutputDTD882991309.DBemployee otdOutputDTD_DBemployee_1, com.stc.connector.appconn.file.FileApplication FileClient_1 ) throws Throwable { FileClient_1.setText( "Delete record .." ); FileClient_1.write(); otdJDBC_1.getDB_EMPLOYEE().delete( input.getText() ); FileClient_1.setText( "Done delete." ); FileClient_1.write(); } } |