Solved

AS/400 ToolBox - com.ibm.as400.access.AS400 class

Posted on 2000-03-19
6
937 Views
Last Modified: 2010-05-18
Hello

In a java program I'm trying to create an AS400 object using the toolBox class's.
In my program I have a java.sql.Connection Object to my AS/400.

making an instance of the AS400 class will open a socket to my AS/400 computer.
the thing is that I already have a Connection to my AS/400.

so my Q is how can I use my current Conection instance to the AS/400 when I'm creating the AS400 instance, because I don't want to create one more socket.


    ASA.
0
Comment
Question by:kingasa
  • 4
  • 2
6 Comments
 
LVL 1

Expert Comment

by:bhagawatula
ID: 2650635
Hi,
From your question I understand that, u have been through the following ways
of establishing a connection to a 400.

Method 1:
                AS400 as400 = new AS400(System, User, Password);

Method 2:
                java.sql.Connection connection =
DriverManager.getConnection("jdbc:as400://" + System, User, Password);


The  question is that, where exactly you are being forced to use the AS400
Class, so that a second socket connection will be established. Can u please explain the requirement.

Is it something like, you want to run an RPG Program(batch) or access
Message Queue etc.,

e.g. In case, if you want to call an RPG Program or any batch command in the
AS400, you have to use only the AS400 class i guess.

Here, I have given a wrapper for Program Call, which basically accepts the
authority, library name, Program Name to be called. Constructors are
overloaded, one for with parameters and without parameters.

Create a sepatate program as follows.Have this as an separate program.


import com.ibm.as400.access.*;

class pgmCall {
      boolean parm;
      String Lib,Pgm;
      AS400 sys;
      ProgramParameter[] Pgmparm;
      public pgmCall(AS400 System,String Library, String Program)
            {
            sys=System;
            Lib=Library;
            Pgm=Program;
            parm=false;
            pgmOpen();
            }
      public pgmCall(AS400 System,String Library, String
Program,ProgramParameter[] Pparm)
            {
            sys=System;
            Lib=Library;
            Pgm=Program;
            Pgmparm=Pparm;
            parm=true;
            pgmOpen();
            }

      void pgmOpen()
      {
      try {
            QSYSObjectPathName pPath = new
QSYSObjectPathName(Lib,Pgm,"PGM");
            ProgramCall pgm = new ProgramCall(sys);
            if(parm)
                  pgm.setProgram(pPath.getPath(),Pgmparm);
            else
                  pgm.setProgram(pPath.getPath());

            System.out.println("Pgm.run() to be run");

               if (pgm.run()!=true)
               {
            System.out.println("Pgm.run() not true");
               }
            else
             {
             }
            System.out.println("Pgm.run() over");
          }
          catch(AS400SecurityException ee)
            {
        System.out.println("pgmCall :"+ ee);
        System.exit(0);
            }

      catch (Exception e)
            {
        System.out.println(e);
        System.exit(0);
            }

    }

public      ProgramParameter[] returnParam()
      {
            return Pgmparm;
      }
}





In any Program, whereever you want to call a Program, you can just code the
following way.



public class RPT extends HttpServlet
{

      AS400 as400;
      pgmCall DAILYSTAT;
 
        try
        {
            DAILYSTAT      = new pgmCall(as400,"TURBO","DAILY_STAT");
/*
as400 is the connection
TURBO is the library name
DAILY_STAT is the Program Name
*/
        }
      catch(Exception Exception2)
            {
            }

}

If the above, does not meet your questions please explain me clearly about
your requirement so that i can try to answer your question precisely.








0
 
LVL 1

Expert Comment

by:bhagawatula
ID: 2655899

Hi,
I am submitting mu comment as answer as I did not get any responce from you .

From your question I understand that, u have been through the following ways
of establishing a connection to a 400.

Method 1:
                AS400 as400 = new AS400(System, User, Password);

Method 2:
                java.sql.Connection connection =
DriverManager.getConnection("jdbc:as400://" + System, User, Password);


The  question is that, where exactly you are being forced to use the AS400
Class, so that a second socket connection will be established. Can u please explain the requirement.

Is it something like, you want to run an RPG Program(batch) or access
Message Queue etc.,

e.g. In case, if you want to call an RPG Program or any batch command in the
AS400, you have to use only the AS400 class i guess.

Here, I have given a wrapper for Program Call, which basically accepts the
authority, library name, Program Name to be called. Constructors are
overloaded, one for with parameters and without parameters.

Create a sepatate program as follows.Have this as an separate program.


import com.ibm.as400.access.*;

class pgmCall {
boolean parm;
String Lib,Pgm;
AS400 sys;
ProgramParameter[] Pgmparm;
public pgmCall(AS400 System,String Library, String Program)
{
sys=System;
Lib=Library;
Pgm=Program;
parm=false;
pgmOpen();
}
public pgmCall(AS400 System,String Library, String
Program,ProgramParameter[] Pparm)
{
sys=System;
Lib=Library;
Pgm=Program;
Pgmparm=Pparm;
parm=true;
pgmOpen();
}

void pgmOpen()
{
try {
QSYSObjectPathName pPath = new
QSYSObjectPathName(Lib,Pgm,"PGM");
ProgramCall pgm = new ProgramCall(sys);
if(parm)
pgm.setProgram(pPath.getPath(),Pgmparm);
else
pgm.setProgram(pPath.getPath());

System.out.println("Pgm.run() to be run");

         if (pgm.run()!=true)
         {
System.out.println("Pgm.run() not true");
         }
else
{
}
System.out.println("Pgm.run() over");
     }
     catch(AS400SecurityException ee)
       {
        System.out.println("pgmCall :"+ ee);
        System.exit(0);
       }

catch (Exception e)
       {
        System.out.println(e);
        System.exit(0);
       }

    }

public ProgramParameter[] returnParam()
{
return Pgmparm;
}
}





In any Program, whereever you want to call a Program, you can just code the
following way.



public class RPT extends HttpServlet
{

AS400 as400;
pgmCall DAILYSTAT;
 
        try
        {
DAILYSTAT      = new pgmCall(as400,"TURBO","DAILY_STAT");
/*
as400 is the connection
TURBO is the library name
DAILY_STAT is the Program Name
*/
        }
catch(Exception Exception2)
{
}

}

If the above, does not meet your questions please explain me clearly about
your requirement so that i can try to answer your question precisely.




 
0
 

Author Comment

by:kingasa
ID: 2657897
bhagawatula ,

All I want to do is excute the CLRPFM command on the AS/400 using the CommandCall class from the ToolBox.




    ASA.  

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:bhagawatula
ID: 2662533
bhagawatula changed the proposed answer to a comment
0
 
LVL 1

Accepted Solution

by:
bhagawatula earned 100 total points
ID: 2662538
import com.ibm.as400.access.*;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;

public class CMDCALLEXAMPLE extends HttpServlet
{

    AS400 as400;
    cmdCall Clrpfm;

    public CMDCALLEEXAMPLE()
    {
    }

    public void init(ServletConfig servletconfig)
        throws ServletException
    {
        super.init(servletconfig);
    }


    public void service(HttpServletRequest httpservletrequest,
HttpServletResponse httpservletresponse)
    {
        PrintWriter printwriter = null;
        HttpSession httpsession = null;
        Connection connection = null;
        ResultSet resultset = null;

        try
        {
            httpsession = httpservletrequest.getSession(true);
            httpservletresponse.setContentType("text/html");
            printwriter = httpservletresponse.getWriter();
            as400 = (AS400)httpsession.getValue("as400");
            connection = (Connection)httpsession.getValue("Connection");
        }
        catch(Exception Exception1)
        {
            printwriter.println("Session Object Retrieval Exception :" +
Exception1);
            printwriter.close();
            return;
        }

    public void CheckMandatoryEntry(String Opt)
    {

    try {
        Clrpfm = new cmdCall(as400,"CLRPFM LIBRARY/FILENAME");
        System.out.println("Batch Command Run Successfully");
            }
        catch(Exception Exception4)
        {
        System.out.println("Command Run Exception "+ Exception4);
        }
    }

}


---------------------------------------
Source Code for cmdCall
======================

import com.ibm.as400.access.*;

class cmdCall {

    String Str;
    AS400 sys;
    public cmdCall(AS400 System,String cmdStr) {
        sys=System;
        Str=cmdStr;
        pgmOpen();
        }

    void pgmOpen()  {
    try {
        CommandCall cmd=new CommandCall(sys);
        System.out.println(Str);
        cmd.run(Str);
            }
        catch(AS400SecurityException ee) {
            System.out.println("cmdCall :"+ ee);
            System.exit(0);
             }
    catch (Exception e)         {
            System.out.println("cmdCall1 :"+ e);
            System.exit(0);
            }
    }
}


0
 

Author Comment

by:kingasa
ID: 3487934
Answer accepted
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
A short film showing how OnPage and Connectwise integration works.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now