⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectjcasapbean.java

📁 BEA WebLogic Server 8.1大全 = BEA webLogic server 8.1 unleashed (美) Mark Artiges等著 袁毅 ... [等] 译 eng
💻 JAVA
字号:
package jcaSAPapp;

import javax.ejb.*;
import java.util.*;
import javax.naming.*;
import com.sap.mw.jco.jra.*;
import javax.resource.cci.*;
import java.rmi.RemoteException;
/**This Class encapsulates the SessionBean for looking up and connecting to
 * our J2EE resource adapter.  the method called is getJCA(String,String) which
 * returns a Vector of String[] containing the data.*/
public class ConnectJCASAPBean implements SessionBean {
  SessionContext sessionContext;
  private String JNDI_NAME = "java:comp/env/eis/SAPJRAFactory";

  public void ejbCreate() throws CreateException {
    /**@todo Complete this method*/
  }
  public void ejbRemove() {
    /**@todo Complete this method*/
  }
  public void ejbActivate() {
    /**@todo Complete this method*/
  }
  public void ejbPassivate() {
    /**@todo Complete this method*/
  }
  public void setSessionContext(SessionContext sessionContext) {
    this.sessionContext = sessionContext;
  }
  /**getJCA(String,String) takes 2 input parameters for the airline and the description
   * of the airline and returns a Vector containing*/
    public Vector getMaterialList(String searchtext, int maxrows) throws RemoteException
      {
        Vector vec = null;

        Connection connection = null;

        try
        {

              InitialContext icon = new InitialContext();
              ConnectionFactory connectionfactory =
                  (ConnectionFactory) icon.lookup(JNDI_NAME);

              // create the connection
              connection = connectionfactory.getConnection();

              // create Interaction object
              Interaction interaction = connection.createInteraction();

              // create Mapped record for BAPI
              MappedRecord in = connectionfactory.getRecordFactory().createMappedRecord("BAPI_MATERIAL_GETLIST");

              // Input
              in.put("MAXROWS", String.valueOf(maxrows));
              // Create Result set for Input Parameters
              ResultSet matnrSelection = (ResultSet)in.get("MATNRSELECTION");
              matnrSelection.moveToInsertRow();
		              matnrSelection.updateString("SIGN", "I");
		              matnrSelection.updateString("OPTION", "CP");
		              matnrSelection.updateString("MATNR_LOW", searchtext);
		  			  matnrSelection.insertRow();

              // get MappedRecord for output
              MappedRecord out = (MappedRecord) interaction.execute(null, in);


              // extract results
              ResultSet matnrList = (ResultSet) out.get("MATNRLIST");

              vec = toVector(matnrList);


              interaction.close();

              return vec;
          }
          catch (Exception e)
          {
            e.printStackTrace();
            throw new RemoteException(e.getMessage(), e);
          }
          finally
          {
              if (connection != null)
              {
                  try
                  {
                      connection.close();
                  }
                  catch(Exception exception1) { }
              }
          }


    }

  private Vector toVector(ResultSet rs){

	  Vector vec = new Vector();
	  try{

	  while(rs.next())
         {
	               vec.add(new String[]{rs.getString(1),rs.getString(2)});
         }

      }catch(Exception e){
		  e.printStackTrace();
		  }
      return vec;

	  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -