本程序参照:http://hi.baidu.com/wangyantsing/blog/item/a984cbfc339212fbfc037f9d.html ,自己练习的代码,测试成功。
// 使用连接池,连接SAP服务器
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import com.sap.mw.jco.*;
public class Test02 {
static final String pool_name = "pool";
public static void main(String[] args) throws IOException{
IRepository repository;
JCO.Client mConnection;
JCO.Pool pool = JCO.getClientPoolManager().getPool(pool_name);
if(pool == null){
java.util.Properties logonprope = new java.util.Properties();
InputStream in = new BufferedInputStream (new FileInputStream("../jexcelapi/test02/src/properties/logon.properties"));
logonprope.load(in);
//在连接池中添加连接的方式有多种,这里仅仅展示了两种方式
JCO.addClientPool( pool_name,
5,
logonprope
);
mConnection = JCO.getClient(pool_name);
try{
mConnection.connect();
System.out.println(mConnection.getAttributes());
}catch(Exception e){
System.err.println("打开或者关闭连接失败");
}finally{
JCO.releaseClient(mConnection);
}
}
}
}
*logon.properties文件的内容如下
jco.client.client=800
jco.client.user=*****
jco.client.passwd=*****
jco.client.ashost=**********
jco.client.sysnr=01