iSeries connection connector program example

For information about the JCA 1.0 specification, see the J2EE Connector Architecture (located on Sun Microsystem's Web site at http://java.sun.com/j2ee/connector/index.html.)

The following code fragment illustrates the coding required for an application component of an iSeries program call connector.

import java.math.*;
import javax.resource.cci.*;
import javax.resource.ResourceException;
import javax.naming.*;
import com.ibm.connector2.iseries.pgmcall.*;
import DPC418PGM;

try
{
Context ic = new InitialContext();

// "eis/pgmcall07m" is the JNDI name for the instance ISeriesPgmCallConnectionFactory as set up
// during ISeries Program Call connector installation and administration
ConnectionFactory cf = (ConnectionFactory) ic.lookup("eis/pgmcall07m");
ISeriesPgmCallConnectionSpecImpl connSpec = new ISeriesPgmCallConnectionSpecImpl();
// the following code is used to override the authentication credential
//connSpec.setServerName("hostname");
//connSpec.setUserName("username");
//connSpec.setPassword("password");
connSpec.setPcmlName(pcmlname);
connSpec.setSessionID(sessionID);

// optionally, set up the library list.
String[] llist = { "userlibrary" };
connSpec.setAS400LibList(llist);

ISeriesPgmCallInteractionSpec interactionSpec = new ISeriesPgmCallInteractionSpec();
interactionSpec.setProgramName("DPC418PGM");

ISeriesPgmCallConnection con = (ISeriesPgmCallConnection) cf.getConnection(connSpec);

// DPC418PGM is the databean class generated from the pcml file, "pcmlname", 
// by ProgramCall Wizard of iSeries Javatooling 
DPC418PGM dataBean = new DPC418PGM();
dataBean.setChar10("data");

ISeriesPgmCallInteraction interaction = (ISeriesPgmCallInteraction)con.createInteraction();
interaction.execute(interactionSpec, dataBean, dataBean);

String strOut = dataBean.getChar10();

con.close();

// release the connection for the session
cf.clearForSessionID("1");
}
catch (NamingException ex)
{
ex.printStackTrace();
}
catch (ResourceException ex)
{
ex.printStackTrace();
}

Run-time exception

ResourceException is used to indicate errors to the caller. For further information, see iSeries connection connector APIs.

Required run-time JAR files

The following jar files are required in the classpath of the application: