Jco Is a high-performance, based on JNI Middleware, which implements SAP Of RFC ( Remote function call ) Protocol.
1,JcoInstallation
From http://files.cnblogs.com/byfhd/jco.rar Download Jco , Unzip the package Librfc32.dll And Sapjcorfc. dll Copy Winnt "system32 Under, Set Sapjco. Jar Add to project Classpath .
2, AndSAPConnection
JcoTwo connection modes are supported,Direct connectionsAndConnection pools.
Direct connections:
Import com. sap. mW. jco .*;
Public tutorialconnect1 (){
Jco. Client mconnection;
Try {
Mconnection = jco. createclient ("001", // sap Client
"", // Userid
"*****", // Password
Null, // Language
"", // Server host name
"00"); // system number mconnection. Connect ();
Mconnection. Disconnect ();
} Catch (exception ex ){
}
}
Connection pools:
Static final string pool_name = "pool ";
Public tutorialconnect2 (){
Jco. Client mconnection;
Try {
Jco. Pool pool = jco. getclientpoolmanager (). getpool (pool_name );
If (pool = NULL ){
Orderedproperties properties = orderedproperties. Load ("/logon. properties ");
Jco. addclientpool (pool_name, // pool name
5, // maximum number of connections
Logonproperties); // Properties
}
Mconnection = jco. getclient (pool_name );
} Catch (exception ex ){
} Finally {//Connect to the connection pool. Otherwise, no available connection is available.
Jco. releaseclient (mconnection );
}
}
Logon. PropertiesFile definition:
Jco. Client. Client = 001
Jco. Client. User = userid
Jco. Client. passwd = ****
Jco. Client. ashost = hostname
Jco. Client. sysnr = 00
3, PairSAPOperation
sap jco. repository objects, including sap RFM runtime environment metadata.
Jco. repository mrepository;
Mrepository = new jco. Repository ("arasoft", mconnection );
The constructor contains two parameters. The first parameter is an arbitrary name, and the second parameter is a connection pool orJco. ClientObject.
Ifunctiontemplate The object contains a specific RFM Metadata, Jco. Function Represents RFM . The relationship between them is similar. Java Medium Class And Object .
ifunctiontemplate Ft = mrepository. getfunctiontemplate ("bapi_salesorder_getlist");
// ft null, it indicates that the parameter is not in sap Find the corresponding RFM
If (FT = NULL) return NULL;
jco. function function = ft. getfunction ();
Jco. parameterlistObject inclusionFunctionInput, output, and table parameters.
Client = jco. getclient (SID );// Slave Pool Obtain Client
Jco. parameterlist input = function. getimportparameterlist ();
// Set the parameter. The parameter name is the second parameter. The parameter value is the first parameter,
Input. setvalue ("0000001200", "customer_number ");
Input. setvalue ("1000", "sales_organization ");
Client.exe cute (function );
Download jco: http://files.cnblogs.com/byfhd/jco.rar