Java连接SAP实例
程序员文章站
2022-07-10 18:30:16
用eclipse時,先導入sapjco3.jar進去。...
用eclipse時,先導入sapjco3.jar進去。
package testsap; import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.util.Properties; import com.sap.conn.jco.JCoDestination; import com.sap.conn.jco.JCoDestinationManager; import com.sap.conn.jco.JCoException; import com.sap.conn.jco.JCoFunction; import com.sap.conn.jco.JCoParameterList; import com.sap.conn.jco.JCoRepository; import com.sap.conn.jco.JCoTable; import com.sap.conn.jco.ext.DestinationDataProvider; public class test { static String ABAP_AS_POOLED = "ABAP_AS_POOL"; static { Properties connectProperties = new Properties(); connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST,"服務器Ip"); connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "連接的Client"); connectProperties.setProperty(DestinationDataProvider.JCO_USER, "Username"); connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "Password"); connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "事例號碼"); connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "語言"); connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3"); connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10"); createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties); } static void createDataFile(String name, String suffix, Properties properties) { File cfg = new File(name + "." + suffix); if (!cfg.exists()) { try { FileOutputStream fos = new FileOutputStream(cfg, false); properties.store(fos, "for tests only !"); fos.close(); } catch (Exception e) { e.printStackTrace(); } } } private void writeArrayToTxt(JCoTable demands, String string) { try { FileWriter fw = new FileWriter(string); for (int i = 0; i < 1; i++) { for (int j = 0; j < 1; j++) fw.write(demands+ "\t"); fw.write("\n"); } fw.close(); } catch (IOException e){ e.printStackTrace(); } } public static void RFC() throws JCoException { String RFCName = "調用的RFC"; JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED); JCoRepository repository = destination.getRepository(); JCoFunction function = repository.getFunction(RFCName); JCoParameterList input = function.getImportParameterList(); input.setValue("要傳的參數", "參數值"); JCoTable tb_list = function.getTableParameterList().getTable("傳表"); tb_list.appendRow(); tb_list.setValue("表中列名","第一行的值"); function.execute(destination); JCoTable codes = function.getTableParameterList().getTable("返回的輸出表"); //控制台輸出返回內容 for (int i = 0; i < codes.getNumRows(); i++) { codes.setRow(i); System.out.println(codes.getString("輸出表的列名") '\t' + codes.getString("輸出表的列名")); } //保存為txt文檔 test wa = new test(); wa.writeArrayToTxt(codes, "my.txt"); } public static void main(String[] args) throws JCoException { RFC(); } }
上面的是單個服務器連接,群組服務器連接,換一下參數就行,下面是群組連接參數:
connectProperties.setProperty(DestinationDataProvider.JCO_R3NAME,"系統ID"); connectProperties.setProperty(DestinationDataProvider.JCO_GROUP,"群組名"); connectProperties.setProperty(DestinationDataProvider.JCO_MSHOST,"服務器IP"); connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT,"client"); connectProperties.setProperty(DestinationDataProvider.JCO_USER,"username"); connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD,"password"); connectProperties.setProperty(DestinationDataProvider.JCO_LANG,"EN"); connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,"10"); connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
本文地址:https://blog.csdn.net/qq_44861248/article/details/107874426
上一篇: 什么是单例模式,他有些什么类型
下一篇: java登录页面的实现步骤
推荐阅读
-
mysql-Java Web连接MySql数据库,修改数据库连接类中的用户名和密码没有效果?
-
access数据库 php adodb连接带密码access数据库实例,测试成功
-
java jdbc连接mysql_MySQL
-
java连接sql server数据库(使用用户sa)
-
java连接Oracle数据库
-
单例 - PHP程序运行的时候,既然是每一个HTTP请求对应一个数据库PDO连接对象实例
-
实例讲解Java 自旋锁
-
Enterprise Manager 无法连接到数据库实例
-
腾讯云创建 SQL Server实例及从本地连接 SQL Server 实例分析
-
java annotation 实例