java 连接SAP 组连接及单链接方式

package main.java.com.platform.wms.util;

import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.ext.DestinationDataProvider;
   
public class SAPConn {
    

    private static final String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";  
    static{  
        Properties connectProperties = new Properties();  
        
        //单链接
       /* connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "127.0.0.1");//服务器  
        connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,  "02");        //系统编号  
        connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "666");       //SAP集团客户端号 
        connectProperties.setProperty(DestinationDataProvider.JCO_USER,   "RF_XXX");  //SAP用户名  
        connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "*******");     //密码  
        connectProperties.setProperty(DestinationDataProvider.JCO_LANG,   "zh");        //登录语言  
        connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "20");  //最大连接数    
        connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "40"); */    //最大连接线程  
        
        //组连接
        connectProperties.setProperty(DestinationDataProvider.JCO_MSHOST, "127.0.0.1");//服务器  
        connectProperties.setProperty(DestinationDataProvider.JCO_MSSERV, "8888");//服务端口  
        connectProperties.setProperty(DestinationDataProvider.JCO_GROUP,  "MC_XXX_ALL");    //组名称  
        connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "888");       //SAP集团客户端号  
        connectProperties.setProperty(DestinationDataProvider.JCO_USER,   "RF_XXX_C101");  //SAP用户名  
        connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "xxxxxx");     //密码  
        connectProperties.setProperty(DestinationDataProvider.JCO_LANG,   "zh");        //登录语言  
        connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "20");  //最大连接数    
        connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "40");     //最大连接线程  
        connectProperties.setProperty(DestinationDataProvider.JCO_MAX_GET_TIME, "240");     //最大连接时间


        createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties);  
    }  
      
    /** 
     * 创建SAP接口属性文件。 
     * @param name  ABAP管道名称 
     * @param suffix    属性文件后缀 
     * @param properties    属性文件内容 
     */  
    private static void createDataFile(String name, String suffix, Properties properties){  
        File cfg = new File(name+"."+suffix);  
        if(cfg.exists()){  
            cfg.deleteOnExit();  
        }  
        try{  
            FileOutputStream fos = new FileOutputStream(cfg, false);  
            properties.store(fos, "for tests only !");  
            fos.close();  
        }catch (Exception e){  
            log.error("Create Data file fault, error msg: " + e.toString());  
            throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);  
        }  
    }  
      
    /** 
     * 获取SAP连接 
     * @return  SAP连接对象 
     */  
    public static JCoDestination connect(){  
        JCoDestination destination =null;  
        try {  
            destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);  
        } catch (JCoException e) {  
            log.error("Connect SAP fault, error msg: " + e.toString());  
        }  
        return destination;  
    }  
    private static Logger log = Logger.getLogger(SAPConn.class); // 初始化日志对象

}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值