JAVA连接sap

JAVA代码: 类SAPLogon. 只是用来登录SAP,其实是为了取得SAP里的 JCO.Repository 对象。
类SAPServer. 用来监听来自SAP的消息。该类必须继承 JCO.Server,因为JCO.SERVER的监听是单独开的一个线程,而监听到有信号来的时候,JCO.SERVER会自动执行其中的protected的方法handleRequest,所以也必须重写该方法。
package javaapplication3;
import com.sap.mw.jco.*;
import com.sap.mw.jco.JCO.Function;
class SAPServer extends JCO.Server
{
public SAPServer(JCO.Repository repo)
{
super ("10.60.203.100", "sapgw01", "MYABC", repo);
}
protected void handleRequest(Function arg0) throws Exception {
JCO.ParameterList output = arg0.getExportParameterList();
output.setValue("Singel Lee", "RETURN_STR");
this.stop();

}

}
class SAPLogon
{
public JCO.Client mConnection;
public JCO.Repository mRepository;
public SAPLogon(String client, String userid, String password, String language,
String ip, String system_number)
{
try {
mConnection = JCO.createClient(client,
userid,
password,
language,
ip,
system_number);
mConnection.connect();
mRepository = new JCO.Repository("Lee", mConnection);
System.out.println("SAP连接成功");
mRepository = new JCO.Repository("my_repository", mConnection);
mConnection.disconnect();
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);

}

}

}
public class Main {

public static void main(String[] args) {
SAPLogon mySAP = new SAPLogon("800", "DEV0008", "*****", "E", "10.60.203.100", "01");
SAPServer myServer = new SAPServer(mySAP.mRepository);

myServer.start();
}
}

你可能感兴趣的:(java)