| Installing Upgrading Designing Configuring Deploying Monitoring Administering Troubleshooting Reference JBI Components | |
| Close Print View | |
| Designing: Prepared Statement |
|
Creating a Runtime Environment
Designing Business Processes in the Sun Business Process Manager
Working with TCP/IP HL7 Collaborations
Developing Sun Master Indexes (Repository)
Developing Sun Master Patient Indexes
Developing OTDs for Application Adapters
Developing OTDs for Communication Adapters
Developing OTDs for Database Adapters
Developing OTDs for Web Server Adapters
Designing with Application Adapters
Designing with Communication Adapters
Designing with Web Server Adapters
Designing with Sun JCA Adapters
Defining Constants and Variables
JDBC Adapter Database Operations (BPEL)
JDBC Adapter Database Operations (JCD)
Sybase Adapter Database Operations (BPEL)
Sybase Adapter Database Operations (JCD)
VSAM Adapter Database Operations (BPEL)
VSAM Adapter Database Operations (JCD)
SQL Server Adapter Database Operations (BPEL)
SQL Server Adapter Database Operations (JCD)
DB2 Database Operations (BPEL)
DB2 Connect Adapter Database Operations (BPEL)
DB2 Connect Adapter Database Operations (JCD)
Oracle Adapter Database Operations (BPEL)
Oracle Adapter Outbound XA Support for BPEL
Oracle Adapter Database Operations (JCD)
Long RAW for Prepared Statements and Stored Procedure support:
A Prepared Statement is a SQL statement which can also contain parameter marker as input holder.
Example: select * from table1 where col1 > ?
This statement selects all the columns from a table called table1 if column col1 is greater than a certain value. The value will be supplied during runtime.
Note - The DB2 Connect Universal Driver only supports Updatable Resultsets for Update and Delete. The Insert operation is not supported. You can use a Prepared Statement to perform the Insert operation.
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 (?, ?, ?, ?, ?)
Note - 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();
}
}
To perform an update operation using Prepared Statement
Assign value to input field.
Execute the executeUpdate() .
This example updates employee records which matches the where clause. The Prepared Statement looks like this:
Update DB_EMPLOYEE set rate = 19 where EMP_NO = ?
Note - The content of the input.getText() file must contain the input value to substitute the parameter marker ?
package prjDB2Connect_JCDjcdALL; public class jcdPsUpdate { 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 ) throws Throwable { FileClient_1.setText( "Update the Rate and Last_update fields using Prepared Statement.. " ); FileClient_1.write(); otdDB2Connect_1.getUpdate_ps().setEmp_no( typeConverter.stringToShort( input.getText(), "#", false, 0 ) ); otdDB2Connect_1.getUpdate_ps().executeUpdate(); FileClient_1.setText( "Done Update." ); FileClient_1.write(); } }