Example: Using message queues (part 2 of 3)

[ Previous part | Next part ]

Use the following as an example for your program.

Note: Read the Code example disclaimer for important legal information.
//////////////////////////////////////////////////////////////////////////////////
//
// Example using the Message Queue function of the IBM Toolbox for Java
//
// This source is an example of IBM Toolbox for Java "Message Queue".
//
//////////////////////////////////////////////////////////////////////////////////

package examples;


import java.io.*;
import java.util.*;
import com.ibm.as400.access.*;

public class displayMessages extends Object
{

   public static void main(String[] parameters)
   {
      displayMessages me = new displayMessages();

      me.Main(parameters);

      System.exit(0);
   }


   void displayMessage()
   {
   }


   void Main(String[] parms)
   {
      try
      {

          AS400 system = new AS400();  Note 1 


                     if (parms.length > 0)
                        system.setSystemName(parms[0]);  Note 2 

      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
   }
}
  1. A program uses the AS400 object to designate which server to connect to. With one exception, all programs that need resources from a server must have an AS400 object. The exception is JDBC. If your program uses JDBC, then the IBM® Toolbox for Java™ JDBC driver creates the AS400 object for the program.
  2. This program assumes the first command line parameter is the name of the server. If a parameter is passed to the program, the setSystemName method of the AS400 object is used to set the system name. The AS400 object also needs server sign-on information:
    • If the program is running on a workstation, the IBM Toolbox for Java program prompts the user for a user ID and password. Note: If a system name is not specified as a command line parameter, the AS400 object also prompts for the system name.
    • If the program is running on the iSeries™ JVM, then the user ID and password of the user running the Java program is used. In this case, the user does not specify a system name, but lets the system name default to the name of the system that the program is running on.

[ Previous part | Next part ]