How to use IBM Toolbox for Java to develop IBM i applications

Source: Internet
Author: User
Tags connection pooling

Overview

IBM Toolbox for Java is a collection of classes for developing Java applications related to IBM I. It includes tools that provide support for various scenarios such as IFS, IBM i System information, client/server, and users can easily use IBM Toolbox for Java Development on other platforms, such as Windows,linux, for applications on IBM i program, for the user's programming and debugging has brought great convenience. On these operating system platforms, we can access an IBM I system through a few lines of simple code, and control and change the system accordingly.

IBM Toolbox for Java is available not only for IBM developers, it also has an open source version of Jtopen for all people to download and use. Jtopen can be downloaded from the SourceForge website. The download and use of Jtopen follow the IBM Public License Agreement (IBM publicly License), which encourages users to develop and improve software, while encouraging the commercialization of software applications.

This article will provide some examples of how to use the various tools provided by IBM Toolbox for Java to access the IBM I system and develop IBM I-related Java programs.

To initialize and establish a connection:

The AS400 class in IBM Toolbox for Java is used to establish a connection to the IBM I system, a class that is simple enough to initialize the AS400 class with the following parameters, Toolbox automatically establishes the connection and logs on to the system as appropriate for the user name:
Listing 1. Using Toolbox to establish a connection

AS400 as400 = new AS400 (SystemName, Username, Password);

If you do not specify a user when initializing the AS400 object, Toolbox will pop up a window at the time of the connection, prompting you to enter the username and password for the IBM i login.

We can also specify the default login user, in the Login box, select "Default User" and "Save Password", so that the next time you log in, you can lose the user name or password, the code is as follows:
Listing 2. Specify the default logon user

AS400 sys1 = new AS400 (systemname); 
AS400 sys2 = new AS400 (systemname); 
try{ 
    Sys1.connectservice (as400.command); 
    Sys2.connectservice (As400.command); 
} catch (Exception e) { 
    e.printstacktrace (); 
}

If we need to access sensitive data on an IBM I system, or the data content that is accessed or stored needs to be encrypted, we can use the SecureAS400 class in Toolbox for Java. This class inherits the AS400 class, and uses the same method as AS400, by simply entering the system name, username, and password. However, secure Sockets Layer (SSL) is used in SecureAS400, so it is more secure and reliable in data interchange.

In addition to creating a new connection directly, we can also use the connection pool to get a connection to the AS400. See the following code:

Listing 3. Use connection pool to get a connection

As400connectionpool As400pool = new As400connectionpool (); 
As400pool.setmaxconnections (128); 
As400pool.fill (SystemName, Username, Password, AS400. DATABASE, m); 
As400pool.getconnection (SystemName, Username, Password, As400.command);

The code above creates a new As400pool as a connection pool connecting the IBM I system, setting the maximum number of connections to 128 and establishing 50 connections for the server. After the connection is established, a connection is obtained from the connection pool, using the username and password. The advantage of using connection pooling is that the use of connection pooling can greatly improve efficiency and reduce the time required to establish a connection when the number of connections required is large. When the number of connections is small, this effect is not obvious, but when the number of connections, the use of connection pool to improve the efficiency of the system will be very obvious.

In addition to AS400, another useful class is as400jping. This class can be used to Ping an IBM I system to query whether the system is currently active, or to query whether a port on the system is available. The following code demonstrates how to use this class:

Use of List 4.as400jping

as400jping pingobj = new As400jping (SystemName, As400.command, false); 
if (pingobj.ping ()) 
    System.out.println ("SUCCESS"); 
else
    System.out.println ("FAILED");

Get IBM I system information using IBM Toolbox for Java:

IBM Toolbox for Java provides a number of tools and class libraries for accessing and controlling system resources, and one of the most common tools is the AS400 class in the "Com.ibm.as400.access" package. AS400 logs in and accesses an IBM I system through a socket connection, and once successful, it provides a variety of interfaces in the form of a method for users to access information about the IBM I system. For example, if you want to get a system name, operating system version, current logged-on user, and CCSID for an IBM I system, we can use the following code to implement:

Listing 5. Get IBM I System Information

AS400 as400 = new AS400 (SystemName, Username, Password); 
System.out.println (As400.getsystemname ()); 
System.out.println (AS400.GETVRM ()); 
System.out.println (As400.getuserid ()); 
System.out.println (As400.getccsid ());

Get system Run information using IBM Toolbox for Java:

IBM Toolbox for Java also provides a number of interfaces for obtaining information about the operation of the system. A commonly used class is systemstatus. This class allows us to access an IBM I system and get the health and information of the current job.

For example, if we want to know how many batch jobs are running in the current system, you can use the following methods:

Listing 6. Get System Run Information

AS400 as400 = new AS400 (SystemName, Username, Password); 
Systemstatus systemstatus = Newsystemstatus (as400); 
try{ 
    System.out.println ("getbatchjobsrunning:"
                + systemstatus.getbatchjobsrunning ());     
} catch (Exception e) { 
    e.printstacktrace (); 
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.