Setting system name, user ID, and password with an AS400 object in the i5/OS 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 (i5/OS™) Java virtual machine (JVM).

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

Examples

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

Example: Creating an AS400 object when the i5/OS JVM is running a Java program

When a Java program is running in the i5/OS JVM, the program does not need to supply a system name, user ID, or password.

Note: You must supply a password 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 i5/OS 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
     // i5/OS 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: Connecting to the current server with a different user ID and password from the program that started the job The Java program can set a user ID and password even when the program is running on the i5/OS 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: Connecting to a different server by using the user ID and password of the job that started the Java program

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

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")