| 
 | 
Hi Tommy,
        From one newbie to another, here is what We hacked out which works
quite well for me...  I am sure that it is all wrong - but it works...
<grin> YMMV
Regards,
Rick
Rick DuVall
Systems Manager
Dealer's Auto Auction of Okc, Inc.
rick@xxxxxxxxxx
(405) 947-2886
http://www.nothingisreal.com/dfki/no-word
    /**
     * Return the Generic As400 Kept in this class
     * 
     * @param None
     * @return As400 Object
     */
    public final static AS400 getMyAs400() throws ConnectGenException {
        if (as400 == null) {
            String initErr = initAccessObjects("xxx.xxx.xxx.xxx"); <put your
address etc. here>
            if (initErr.trim().length() > 0) {
                throw new ConnectGenException(initErr);
            }
        }
        return as400;
    }
    /**
     * Return the Generic Connection Object Kept in this class
     * 
     * @param None
     * @return Connection Object
     */
    public final static Connection getMyConnection() throws
ConnectGenException {
        if (conn == null) {
            String initErr = initAccessObjects("xxx.xxx.xxx.xxx");
            if (initErr.trim().length() > 0) {
                throw new ConnectGenException(initErr);
            }
        }
        return conn;
    }
    /**
     * Initialize the objects that access the iSeries. The goal here is to
     * prevent a situation where calls to an unmarshaller continually cause
new
     * connections to the iSeries to be established. The overhead for that
     * condition has been found to be burdensome.
     * 
     * @throws Exception
     */
    private static String initAccessObjects(String systemAddress) {
        String mthNam = "initAccessObjects";
        //String mPfx = msgPfx(mthNam);
        String rtnErr = "";
        //dftFilSep = System.getProperty("file.separator"); 
        // Create an AS400 object for the server that has the data queues.
        if (as400 == null) {
            as400 = new AS400(systemAddress);
            try {
                as400.connectService(AS400.COMMAND);
            } catch (AS400SecurityException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //prt((mPfx + "as400 null?  " + (as400 == null ? true : false)), 2);
        /*
         * CrtDerDoc000 needs to access the system time. And who knows what
else
         * downstream may?
         */
        //iTGet = new GetiSeriesDateTime3(as400);
        //prt((mPfx + "Back from constructor of GetiSeriesDateTime3
object."), 2);
        if (conn == null) {
            conn = getConnection();
            if (conn == null) {
                rtnErr = "Unable to establish Connection object.";
            } else {
                UserInfoBean myUser = new UserInfoBean();
                myUserid = as400.getUserId().toString();
            }
        }
        return rtnErr;
    }
    /**
     * Get a connection to the iSeries that will persist throughout the
picture
     * numbering process.
     * 
     * @param host
     * @return
     */
    private static Connection getConnection() {
        String mthNam = "getConnection";
        String errMsg = "";
        Connection rtnCon = null;
        try {
            // The DriverManager must be aware that there is a JDBC driver
            // available
            // to handle a user connection request. The following line
causes
            // the
            // native JDBC driver to be loaded and registered with the
            // DriverManager.
            // Class.forName("com.ibm.db2.jdbc.app.DB2Driver");
            // Create the database Connection object that this program uses
in
            // all
            // the other method calls that are made. The following code
            // specifies
            // that a connection is to be established to the local database
and
            // that connection should conform to the properties that were
set up
            // previously (that is, it should use the user ID and password
            // specified).
            DriverManager
                    .registerDriver(new
com.ibm.as400.access.AS400JDBCDriver());
            //          Get a connection to the database. Since we do not
            //          provide a user id or password, a prompt will appear.
            //
            //          Note that we provide a default schema here so
            //          that we do not need to qualify the table name in
            //          SQL statements.
            //
            rtnCon = DriverManager
                    .getConnection("jdbc:as400://192.168.0.1");
        } catch (SQLException sqle) {
            sqle.printStackTrace();
        }
        return rtnCon;
    }
    public String getMyClassName() {
        String myName = "EntityAccessJdbc";
        String qualName = this.getClass().getName();
        int lastDot = qualName.lastIndexOf(".");
        if (lastDot > 0) {
            myName = qualName.substring((lastDot + 1), qualName.length())
                    .trim();
        }
        return myName;
    }
    private String msgPfx(String methodName) {
        return myName + "." + methodName.trim() + "():  ";
    }
    
    private static AS400JDBCDriver as400JdbcDriver = null;
    private String myName = "";
    private static AS400 as400 = null;
    
    private static String myUserid = null;
    private String dftFilSep = "";
    private static Connection conn = null;
    private Statement stm = null;
 
-----Original Message----- From: java400-l-bounces@xxxxxxxxxxxx [mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of Holden Tommy Sent: Friday, February 09, 2007 9:44 AM To: java400-l@xxxxxxxxxxxx Subject: Using JT400. Ok I'm trying to figure this out. Here is the code: import com.ibm.as400.access.AS400; import com.ibm.as400.access.AS400SecurityException; class Base extends Object { public static void main(String args[]) { int as400number; AS400 myas400 = new AS400(); as400number = AS400.SIGNON; try { myas400.validateSignon(); } catch (AS400SecurityException i) {} catch (Exception e){} ObjectDef iObject = new ObjectDef(); if (args.length == 0) { // do nothing } if (args.length == 1) { iObject.Name = args[0]; iObject.Library = "*LIBL"; } if (args.length == 2) { iObject.Name = args[0]; iObject.Library = args[1]; } if (args.length == 3) { iObject.Name = args[0]; iObject.Library = args[1]; iObject.ObjectType = args[2]; } System.out.println(); System.out.println(iObject.Name); System.out.println(iObject.Library); System.out.println(iObject.ObjectType); } } According to what I have read when the AS400 myas400 = new AS400(); is executed I should be prompted for sign on credentials (it's likely something I have misunderstood). When it hits that line no prompt appears and it seems to just step into the com.ibm.whatever and return. Also if I pass the value *PGM as a variable it replaces the constant *PGM with the package name. Please help a newbie....i'll buy a Krystal burger & we can all split it. Thanks, Tommy Holden -- This is the Java Programming on and around the iSeries / AS400 (JAVA400-L) mailing list To post a message email: JAVA400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/java400-l or email: JAVA400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/java400-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.