Vous êtes sur la page 1sur 3

Sorry this is long but I didn't want to leave anything out because I am new at this/ticked/and increasingly bitter.

I have read a couple of books on JAVA and wrote several little classes that run on my PC, no big deal. Then I decided to take the next step and see if I could right a program to pull some file information from the 400. I looked through Don Denoncourt's book 'JAVA Application Strategies for the iSeries & AS/400' and saw a small simple program that prints out a file out of QIWS that all AS/400's are shipped with (so he says). I did verify the file is there and it has some records in it. I did have some difficulties getting the program to compile,it couldn't find the jt400.jar file that needed to be placed on the PC. I straightened out my PATH and CLASSPATH variables and was able to get it to compile. When I try to run it from a DOS prompt in blows up in my face with the following: C:\Program Files\Java\jdk1.5.0_07>java ListRecords Exception in thread "main" java.lang.NoClassDefFoundError: ListRecords (wrong na me: jt400/ListRecords) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknow n Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) C:\Program Files\Java\jdk1.5.0_07> Here is the source code: package jt400; import import import import java.io.*; java.util.*; java.math.*; com.ibm.as400.access.*;

public class ListRecords { public ListRecords() { // Step 1: // Connect to an AS/400 AS400 system = new AS400();

// Step 2: // Specify file location QSYSObjectPathName filePathName = new QSYSObjectPathName("QIWS","QCUSTCDT","FILE"); SequentialFile theFile = new SequentialFile(system,filePathName.getPath()); // Step 3: // Retrieve a record format AS400FileRecordDescription recDesc = new AS400FileRecordDescription(system, filePathName.getPath()); try { theFile.setRecordFormat(recDesc.retrieveRecordForm at()[0]); // Step 4: // Open the File theFile.open(AS400File.READ_ONLY, 0, AS400File.COMMIT_LOCK_LEVEL_NONE); // Step 5: // Read a record for (Record record = theFile.readNext(); record != null; record = theFile.readNext()) { // Step 6: // Retrieve the field values of that record BigDecimal CustnoField = (BigDecimal) record.getField( "CUSNUM" ); String NameField = (String) record.getField( "LSTNAM" ); System.out.println(NameField + CustnoField); } // Close the file theFile.close(); } catch (Exception e) { System.out.println( "Error occurred listing the file."); try { theFile.close(); } catch(Exception x) { System.out.println( "Error occurred closing the file."); } System.exit(0); } System.exit(0); }

public static void main(String[] args) { ListRecords listRecords = new ListRecords(); } } I don't know if my path or classpath is wrong but it does compile so I would think I should be Ok with that. I am a little concerned about how it can find the 400 from what code there is. My PC is connect to 3 400's so I don't know how it would know which one to try and pull data from. The book did say the code should work 'as is'. I must be the unluckiest SOB alive because 'as is' rarely stops at my door to say howdy. If you have gotten this far I thank you and if you could point me in the correct direction on getting this thing to run I would be happy.

Vous aimerez peut-être aussi