FileDocCategorySizeDatePackage
SampleResultSetScenario.javaAPI DocGlassfish v2 API4025Fri May 04 22:35:40 BST 2007sample

SampleResultSetScenario

public class SampleResultSetScenario extends Object
SampleResultSetScenario.java

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

  
public voidmethod()

    
    try {
      Context nc = new InitialContext();

      // JNDI lookup for ConnectionFactory
      ConnectionFactory cf = (ConnectionFactory)nc.lookup(
				 "java:comp/env/eis/ConnectionFactory");
      Connection cx = cf.getConnection();

      // Create an Interaction. 
      Interaction ix = cx.createInteraction();

      // Create an InteractionSpec and set properties.
      InteractionSpecImpl ixSpec = new InteractionSpecImpl();
      ixSpec.setFunctionName("<NAME OF FUNCTION>");
      ixSpec.setInteractionVerb(InteractionSpec.SYNC_SEND_RECEIVE);

      RecordFactory rf = cf.getRecordFactory();
      
      // Create an input MappedRecord. The component code adds values
      // based on the meta information it has accessed from the metadata
      // repository. The name of the Record acts as a pointer to the 
      // meta information (stored in the metadata repository) for a 
      // specific record type.
      MappedRecord input = rf.createMappedRecord("Name of Record");
      input.put("<key: element1>", new String("<VALUE1>"));
      input.put("<key: element2>", new String("<VALUE2>")); 

      // Execute the Interaction
      ResultSet rs = (javax.resource.cci.ResultSet)ix.execute(ixSpec, input);

      // Iterate over the ResultSet. The example here positions the
      // cursor on the first row and then iterates forward through 
      // the contents of the ResultSet. The getXXX methods are used
      // to retrieve column values:      
      rs.beforeFirst();
      while (rs.next()) {
	// Look at the current row of the resultSet
      }
    }
    catch (NamingException ne) {
      return;
    }
    catch (ResourceException e) {
      return;
    }    
    catch (SQLException e) {
      return;
    }