COBOL 调用存根 Java 类使用示例
COBOL 调用存根 Java™ 类使用示例显示批处理应用程序可如何使用 COBOL 容器调用 COBOL 过程。
在此示例中,事件会按以下顺序发生:
- 创建 COBOL 容器。
- 创建 COBOL 过程调用存根。
- 参数数据设置为 COBOL 过程调用存根。
- 在容器上设置共享 DB2® 连接。
- 使用容器调用 COBOL 过程。
使用容器调用 COBOL 过程至少需要执行步骤 1、步骤 2 和步骤 5。步骤 3 和步骤 4 是可选步骤。仅当 COBOL 过程接收参数时需要执行步骤 3,仅当 COBOL 过程访问 DB2 时需要执行步骤 4。
import com.ibm.websphere.batch.ilc.ILContainerFactory;
import com.ibm.websphere.batch.ilc.ILContainer;
import com.ibm.websphere.batch.ilc.ILContainerException;
import com.ibm.websphere.batch.ilc.ILProcedureException;
import com.ibm.ws.batch.ilc.sample.Sample;
import com.ibm.ws.batch.ilc.sample.parameters.SampleDataBinding;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.Connection;
try {
// Create the container.
ILContainer container = ILContainerFactory.getFactory().create();
// Create target procedure using call stub.
Sample proc = new Sample();
// Set parameters.
SampleDataBinding binding = proc.getSampleDataBinding();
binding.setCDummy("foo");
binding.setIlen((short)employeeNumber);
// Set db2 connection for use by COBOL (if necessary).
// InitialContext ic = new InitialContext();
// DataSource datasourceType2 = (DataSource) ic.lookup(jdbcJndi);
// Connection connectionType2 = datasourceType2.getConnection();
// container.setDB2Connection(connectionType2);
// Invoke the COBOL procedure.
int rc = container.invokeProcedure(proc);
}
catch (ILProcedureException) {
…
}
catch (ILContainerException) {
…
}