RFC第一种写法:不生成配置文件,直接连接
java
package com.kaka.workflow.utils;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.ext.DestinationDataEventListener;
import com.sap.conn.jco.ext.DestinationDataProvider;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Properties;
class ConnSAPProperties implements DestinationDataProvider {
public Properties getDestinationProperties(String destinationName) {
Properties properties = new Properties();
properties.setProperty(DestinationDataProvider.JCO_ASHOST, "IP地址");
properties.setProperty(DestinationDataProvider.JCO_SYSNR, "编号");
properties.setProperty(DestinationDataProvider.JCO_CLIENT, "客户端");
properties.setProperty(DestinationDataProvider.JCO_USER, "账户名");
properties.setProperty(DestinationDataProvider.JCO_PASSWD, "密码");
properties.setProperty(DestinationDataProvider.JCO_LANG, "ZH");
return properties;
}
public void setDestinationDataEventListener(DestinationDataEventListener eventListener) {}
public boolean supportsEvents() { return false; }
}
/***
* @MethodName: ConnSAP
* @Description: 连接SAP
* @Param:
* @return:
* @Author: kaka
* @Date: 2023/9/18 17:33
*/
public class ConnSAP {
private static Log log = LogFactory.getLog(ConnSAP.class);
public static JCoDestination Connect() {
ConnSAPProperties provider = new ConnSAPProperties();
com.sap.conn.jco.ext.Environment.registerDestinationDataProvider(provider); //实例化
JCoDestination destination = null;
try {
destination = JCoDestinationManager.getDestination("ABAP_AS_POOLED");
} catch (Exception e) {
e.printStackTrace();
}
log.info("provider>>"+provider);
return destination;
}
public static void main(String[] args) {
JCoDestination connect = ConnSAP.Connect();
System.out.println("connect>>>>>"+connect);
}
}
运行结果:成功了>>>