Setting system name, user ID, and password with an AS400 object in the OS/400 Java virtual machine

The AS400 object allows special values for system name, user ID, and password when the Java program is running on the IBM Developer Kit for Java (OS/400) Java virtual machine (JVM).

When you run a program on the OS/400 JVM, be aware of some special values and other considerations:

The following examples show how to use the AS400 object with the OS/400 JVM.

Example 1: When a Java program is running in the OS/400 JVM, the program does not have to supply a system name, user ID, or password.

A password must be supplied when using record-level access.

If these values are not supplied, the AS400 object connects to the local system by using the user ID and password of the job that started the Java program.

When the program is running on the OS/400 JVM, setting the system name to localhost is the same as not setting the system name. The following example shows how to connect to the current server:

     // Create two AS400 objects.  If the Java program is running in the
     // OS/400 JVM, the behavior of the two objects is the same.
     // They will connect to the current server using the user ID and
     // password of the job that started the Java program.
     AS400 sys  = new AS400()
     AS400 sys2 = new AS400("localhost")

Example 2: The Java program can set a user ID and password even when the program is running on the OS/400 JVM. These values override the user ID and password of the job that started the Java program.

In the following example, the Java program connects to the current server, but the program uses a user ID and password that differs from those of the job that started the Java program.

     // Create an AS400 object.  Connect to the current server but do
     // not use the user ID and password of the job that started the
     // program. The supplied values are used.
     AS400 sys = new AS400("localhost", "USR2", "PSWRD2")

Example 3: A Java program that is running on one server can connect to and use the resources of other iSeries systems.

If *current is used for user ID and password, the user ID and password of the job that started the Java program is used when the Java program connects to the target server.

In the following example, the Java program is running on one server, but uses resources from another server. The user ID and password of the job that started the Java program are used when the program connects to the second server.

     // Create an AS400 object. This program will run on one server
     // but will connect to a second server (called "target").
     // Because *current is used for user ID and password, the user 
     // ID and password of the job that started the program will be
     // used when connecting to the second server.
     AS400 target = new AS400("target", "*current", "*current")