[ Simple programming examples ]
Use the following as an example for your program. The example includes detailed explanations about key lines in the code. You can view the detailed explanations in the following ways:
Note: Read the Code example disclaimer for important legal information.
////////////////////////////////////////////////////////////////////////////////// // // Example using the IBM Toolbox for Java's access class, CommandCall. // // This source is an example of IBM Toolbox for Java "Job List". // ////////////////////////////////////////////////////////////////////////////////// // // The access classes of the Toolbox are in the com.ibm.as400.access.package. // Import this package to use the Toolbox classes. // ////////////////////////////////////////////////////////////////////////////////// import com.ibm.as400.access.*; public class CmdCall { public static void main(String[] args) { // Like other Java classes the Toolbox classes throw // exceptions when something goes wrong. These must be // caught by programs that use the Toolbox. tryNote 1{ AS400 system = new AS400(); CommandCall cc = new CommandCall(system);Note 2
cc.run("CRTLIB MYLIB");Note 3
AS400Message[] ml = cc.getMessageList();Note 4
for (int i=0; i<ml.length; i++) { System.out.println(ml[i].getText());Note 5
} } catch (Exception e) { e.printStackTrace(); } System.exit(0); } }
Toolbox for Java uses the "AS400" object to identify the target server. If you construct the AS400 object with no parameters, Toolbox for Java prompts for the system name, userid and password. The AS400 class also includes a constructor that takes the system name, userid and password.
Use the Toolbox for Java CommandCall object to send commands to the server. When you create the CommandCall object, you pass it an AS400 object so that it knows which server is the target of the command.
Use the run() method on the command call object to run a command.
The result of running a command is a list of OS/400 messages. The Toolbox represents these messages as AS400Message objects. When the command is complete, you get the resulting messages from the CommandCall object.
Print the message text. Also available are the message ID, message severity, and other information. This program prints only the message text.