× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I have very little java skills , if even that much :-)

But I needed a program, that I could run via a runrmtcmd from the as/400, to
a PC,  but then I wanted the PC based java program, to update a table on the
as/400, regarding certain status, about a file...

This program needs to be ran, a lot, on the PC...  So I was wondering if I
could get a few comments and suggestions to let me know, if I wrote this
program in the most stable way...  Memory leaks, jdbc
opening/closing/registering, that would only surface after many days of use,
or maybe there is a better way to execute jdbc operations..  I pulled the
current code from various places on the web, and I have no idea if I did it
right...  It works, but I don't know for how long :-)
Please let me know...

Thank you,  tim

/**

commandline example:
   -oC:\edi\OfficeDepot\out\OFFICE_DEPOT_850_64.edi 
   -s172.16.1.19 
   -p037837.RA.EDI 
   -cc:\edi\officedepot\out\ 
   -tedilib.edifile 
   -fFTP_OUTBOX_BEFORE_SEND

 * @author Tim-H
 *
 * To change this generated comment edit the template variable
"typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */

import java.io.*;
import java.sql.*;

public class edifilecheck
{

// Parmaters
//     1.  as400system = xxx.xx.x.xx
//     2.  poid number in the bootstrap that were looking for.  
//     3.  original edi mapped file, with path, so we can remove the path,
and
//             append the path we need to verify.
//     4.  Path to check for a file.
//     5.  Field to update in the bootstrap table.
//
//



        public static void main(String[] args)
        {



        String FILEFOUND = "?";

                String system             = null;
                String ponumber           = null;
                String originalmappedfile = null;
                String checkpath          = null;
                String table              = null;
                String updatefield        = null;

                int k = 0;
                while ( args.length > k )
                {
                        if ( args[k].startsWith("-s") )
                                system = args[k].substring(2);
                        if ( args[k].startsWith("-p") )
                                ponumber= args[k].substring(2);
                        if ( args[k].startsWith("-o") )
                                originalmappedfile = args[k].substring(2);
                        if ( args[k].startsWith("-c") )
                                checkpath = args[k].substring(2);
                        if ( args[k].startsWith("-f") )
                                updatefield = args[k].substring(2);
                        if ( args[k].startsWith("-t") )
                                table = args[k].substring(2);

                        k++;
                }

                System.out.println("System IP : "+system);
                System.out.println("PO NUMBER : "+ponumber);
                System.out.println("TABLE     : "+table);
                System.out.println("TAB-FIELD : "+updatefield);
                System.out.println("ORIGINAL  : "+originalmappedfile);
                System.out.println("CHECK PATH: "+checkpath);

if (k != 6) {
        System.out.println("NOT ENOUGH PARAMETERS");
        System.exit(0);
           
}



                File originalfile = new File(originalmappedfile);

                System.out.println("FILENAME  : "+originalfile.getName());



//              System.out.println(originalfile.getName());
//              System.out.println(originalfile.getPath());
//              System.out.println(originalfile.getParent());
//              System.out.println(File.separatorChar);
//              if(originalfile.exists())
//              System.out.println("OR-FOUND");
//                 else
//              System.out.println("OR-NOTFOUND");
                
                // We need to seperate the filename portion of the original
mapped
                // file, to extract the name, so we can append the path we
really want
                // to verify the file...
                
                String verifyfile = checkpath + originalfile.getName();
                System.out.println("VERIFYFILE: "+verifyfile);
                File ftVerifyfile = new File(verifyfile);
                
                if(ftVerifyfile.exists()) {
                System.out.println("FOUND     : "+ftVerifyfile.getPath());
                        FILEFOUND = "Y";
                }
                   else {
                    System.out.println("NOTFOUND  :
"+ftVerifyfile.getPath());
                        FILEFOUND = "N";
                   }            
                Connection con = null;
                
                try {
                        DriverManager.registerDriver(new
com.ibm.as400.access.AS400JDBCDriver());
                        con = DriverManager.getConnection
("jdbc:as400://"+system,"username","password");

                        // Run an SQL SELECT statement
                        Statement stmt = con.createStatement ();

          String sqltext = "SELECT * FROM "+table+ " where poid =
'"+ponumber+"'";

                        System.out.println("SQLTEXT   : " +sqltext);
                        ResultSet rs = stmt.executeQuery (sqltext);

                        // Show what happened before the update

                        // Display each row (record) retrieved by the SQL
statement
                        while (rs.next ()) {
                                System.out.println("BEFORE");
                                System.out.println("UPDATEFLD :
"+rs.getString(updatefield));
                                System.out.println("POID      :
"+rs.getString("POID"));
                                }
                        rs.close ();

                        
                        // update the field, if it needs to be...

            String sqlupdate =
               "UPDATE "+table+" SET "+updatefield+" = '"+FILEFOUND+ 
                 "' WHERE POID = '"+ponumber+"'";
                        System.out.println("SQLUPDTEXT: "+sqlupdate);
                        System.out.println("UPDATE    : "+stmt.executeUpdate
(sqlupdate));
                        
                        // Show what happened after the update
                        
                        rs = stmt.executeQuery (sqltext);

                        // Display each row (record) retrieved by the SQL
statement
                        while (rs.next ()) {
                                System.out.println("AFTER");
                                System.out.println("UPDATEFLD :
"+rs.getString(updatefield));
                                System.out.println("POID      :
"+rs.getString("POID"));
                                }
                        rs.close ();
                        
                        
                        
                        
                        stmt.close ();
                  }

                 catch (Exception e) {
                  System.out.println ("DATABASE UPDATE ERROR: " +
e.getMessage());
                  }

                 finally {
                   try {
                         con.close ();
                   }
                 catch (SQLException e) {
                 }
                 }
        }
}



This e-mail message, including any attachments, is for the sole use of the
intended recipient(s) and may contain confidential or privileged
information.  Any unauthorized review, use, disclosure or distribution is
prohibited.  If you are not the intended recipient, please contact the
sender by reply e-mail and destroy the message.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 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.