SAP JCO 备份

package com.mg.sap.ui;

import com.sap.mw.jco.*;
import com.sap.mw.jco.JCO.PoolManager;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
 *
 * @author fred
 */
public class SAPQuery {

    //private static JCO.Client mConnection;
    private static final String SAPHR_POOL_NAME = "SAP_Poolssss";

 

    public static void getSAPPoolConnection() throws IOException {
  PoolManager clientPoolManager = JCO.getClientPoolManager();
  //JCO.Client mClient =null;
  
  try{
   JCO.Pool pool = clientPoolManager.getPool(SAPHR_POOL_NAME);
   if (pool == null) {
    Properties props = new Properties();
    InputStream is = SAPQuery.class.getResourceAsStream("SAPLogon.properties");
    props.load(is);
//    JCO.addClientPool(SAPHR_POOL_NAME, // pool name
//      22, // maximum number of connections
//      "100",
//      "VSC066",
//      "123888",
//      "en",
//      "192.168.163.6",
//      "00"); // properties
    JCO.addClientPool(SAPHR_POOL_NAME, // pool name
      10, // maximum number of connections
      props); // properties    
   }
   //mConnection = JCO.getClient(SAPHR_POOL_NAME);


  }catch (Exception ex) {
   System.err.println(ex.getMessage());
  }
  finally{
   //JCO.releaseClient(mConnection);
  }
  
  //return mClient;
 }


    public static void setConnection(){
        try{
//            mConnection = JCO.createClient("100",
//                                           "vsc066",
//                                           "123888",
//                                           "en",
//                                           "192.168.163.6",
//                                           "00");
        }catch(Exception ex){
           
        }

    }
   
 
    public static void queryPurchse() throws IOException{
      //setConnection();
      JCO.Client client; 
     
      getSAPPoolConnection();
  

      IRepository myRepository = JCO.createRepository("MYRepository", SAPHR_POOL_NAME);
      System.out.println(myRepository.toString());
      String strFunc = "Z_DDXI_RFC";
      IFunctionTemplate ft = myRepository.getFunctionTemplate("Z_DDXI_RFC");
      JCO.Function funGetList = ft.getFunction();
      JCO.ParameterList input = funGetList.getImportParameterList();
      input.setValue("AA", "CARRID");

      client = JCO.getClient(SAPHR_POOL_NAME);
      client.execute(funGetList);

      JCO.Table tDateRange = funGetList.getTableParameterList().getTable("DATA");
      System.out.println("tDateRange:"+tDateRange.getNumRows());
      for (int i = 0; i < tDateRange.getNumRows(); i++) {
        tDateRange.setRow(i);
        System.out.println("Record ["
                            + tDateRange.getString("CARRID")    + "] NUMBER= "
                            + tDateRange.getString("CONNID")    + " COUNTYFR= "
                            + tDateRange.getString("COUNTRYFR") + " CITYFROM= "
                            + tDateRange.getString("CITYFROM"));
      }   
    }


    public void closeConnection(){

        //mConnection.disconnect();

    }
   


    public static final void main(String[] args){  
     try {
      queryPurchse();
  } catch (IOException e) {
   e.printStackTrace();
  }
    }    
   
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22367662/viewspace-684351/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/22367662/viewspace-684351/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值