Part 1: Specifying parameters as single String values

The JCo API offers eight distinct JCO.createClient() methods to establish a connection to the SAP application server. This handy step-by-step guide reviews these mechanisms and offers some recommendations on the best way to pass system parameters to an SAP JCo connection.

import com.sap.mw.jco.*;
...
/* JCO.createClient(SAP_CLIENT, USER_ID, PASSWORD, LANGUAGE, HOST_NAME, SYSTEM_NUMBER);
*/

JCO.Client connection = JCO.createClient("100", "myuserid", "mypassword", "EN", "mysaphost", "00");

connection.connect();
...
connection.disconnect();
As you can see, the connection code is very simple. In fact, you could simply cut and paste the above code into your own application, replace the string values, and connect to SAP. Obviously, maintaining the system connectivity with this code would be difficult, as you would need to search and manually replace each occurrence of each string value.

A slightly more elegant solution would be to declare each value as a global, class-level variable:

public static final String SAP_CLIENT = "100";
By declaring the value public, you create visibility for this value within any generated Javadoc documentation. By declaring it final and assigning it a value, no other code can modify the value. Of course, by hardcoding the password inside a Java class, you run the risk that someone could decompile the source to get at your plaintext password. This connection technique should only be used in development situations, where strong security is not a priority.


GETTING CONNECTED WITH JCO

 Home: Introduction
  Part 1: Specifying parameters as single String values
 Part 2: Specifying parameters using a String array
 Part 3: Specifying parameters using an external properties file
 Part 4: Specifying parameters with a custom properties file
 Review: Conclusion and more resources
This was first published in July 2005

Dig deeper on SAP Web applications

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close