AS/400 Toolbox for Java \ Tips for programming \ Java virtual machine for AS/400 \ Setting system name, userID, password

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

The AS400 object allows special values for system name, user ID, and password when the Java program is running on the Java virtual machine for AS/400.

When you run a program on the Java virtual machine for AS/400, be aware of some special values and other considerations:

The following examples show how to use the AS400 object with the Java virtual machine for AS/400.

Example 1: When a Java program is running in the Java virtual machine for AS/400, 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 Java virtual machine for AS/400, 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 AS/400:

                       // Create two AS400 objects.  If the Java program is
                       // running in the Java virtual machine for AS/400,
                       // the behavior of the
                       // two objects is the same.  They will connect to the
                       // current AS/400 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 Java virtual machine for AS/400. 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 AS/400, 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
                       // AS/400 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 AS/400 can connect to and use the resources of other AS/400 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 AS/400.

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

                       // Create an AS400 object.  This program will run on
                       // one AS/400 but will connect to a second AS/400
                       // (called "target").  Since *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 AS/400.
                       // second AS/400.
     AS400 target = new AS400("target", "*current", "*current")

[ Information Center Home Page | Feedback ] [ Legal | AS/400 Glossary ]