Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

AS/400 connectivity using java by jt400 api

843854Jun 20 2003 — edited Jun 20 2003
I am making a project on Java Swing. I am having an AS/400 machine i am saving the spool files on AS/400 Machine as .txt and accessing it from a remote Windows Machine. I have made an UI to connect it to the AS/400 machine using JT400 API's. I am having 300 spool files(.txt) in the library on AS/400 machine. I m accessing this library to get the list of spool files basically .txt files. Now I am using JT400 OpenAsynchronously method but the program gets hanged over there and displays on 25 files. I don't know what to do please help


Akhil


Code:--------------------------------------------------

public Vector listSpooledFiles()

{
Vector rowData = new Vector();

// this.printQue = printQue;
try
{
String strSpooledFileName;
boolean fCompleted = false;
int listed = 0, size;

System.out.println(" inside method....1");
//System.out.println("Now receiving all spool files synchrously");
SpooledFileList splfList = new SpooledFileList(as400);
splfList.setUserFilter(userId);
//if((printQue.equalsIgnoreCase("*ALL"))||(printQue.equals("")))
//if((printQue.equalsIgnoreCase("*ALL")))
splfList.setQueueFilter("/QSYS.LIB/%ALL%.LIB/%ALL%.OUTQ");

// else
//splfList.setQueueFilter("/QSYS.LIB/%LIBL%.LIB/"+printQue+".OUTQ");
//splfList.setQueueFilter("/QSYS.LIB/%LIBL%.LIB");


// wait for the list to complete
//splfList.waitForListToComplete();
// add the listener.
System.out.println(" inside method....2");
splfList.addPrintObjectListListener(this);
System.out.println(" inside method....3");
// open the list, openAsynchronously returns immediately
splfList.openAsynchronously();
System.out.println(" inside method....4");

do
{
System.out.println(" inside do....1");
// wait for the list to have at least 25 objects or to be done
waitForWakeUp();
System.out.println(" inside method....1.2");
fCompleted = splfList.isCompleted();
System.out.println(" inside method....1.3");
size = splfList.size();
System.out.println(" inside method....1.4");
System.out.println(size+"::size of files");
//System.out.println("sizeOfList......"+size);
// output the names of all objects added to the list
// since we last woke up
while (listed < size)
{
System.out.println(" inside method....1.5");
if (fListError)
{
System.out.println(" ..Exception on list - " + listException);
break;
}
System.out.println(" inside method....1.6");


SpooledFile splf = (SpooledFile)splfList.getObject(listed++);

}

} while (!fCompleted);
System.out.println(size+"::Size");

//splfList.removePrintObjectListListener(this);

System.out.println(" inside method....1.7");
Enumeration enum = splfList.getObjects();
System.out.println(" inside method....1.8");

while(enum.hasMoreElements())
{

SpooledFile splf = (SpooledFile) enum.nextElement();
if(splf != null)
{
Vector tmp = new Vector();

String fileName = splf.getStringAttribute(SpooledFile.ATTR_SPOOLFILE);

int fileNo = splf.getNumber();
String jobName = splf.getJobName();
String jobUser = splf.getJobUser();
String jobNo = splf.getJobNumber();
Integer page =splf.getIntegerAttribute(SpooledFile.ATTR_PAGES);
String date=splf.getStringAttribute(SpooledFile.ATTR_DATE);
String time=splf.getStringAttribute(SpooledFile.ATTR_TIME);
date=date.substring(1);
StringBuffer sbdate= new StringBuffer(date);
sbdate=sbdate.insert(2,"/");
sbdate=sbdate.insert(5, "/");
StringBuffer sbtime=new StringBuffer(time);
sbtime=sbtime.insert(2,":");
sbtime=sbtime.insert(5,":");
date=sbdate.toString();
time=sbtime.toString();

if((!fileName.equals("QPJOBLOG")) && (!fileName.equals("QPDSPJOB")) && (!fileName.equals("QPSRVDMP")))
{


// For the JCheckBox
tmp.addElement(new Boolean(false));
tmp.addElement(fileName);
tmp.addElement(new Integer(fileNo));
tmp.addElement(jobName);
tmp.addElement(jobUser);
tmp.addElement(jobNo);
tmp.addElement(page);
tmp.addElement(date);
tmp.addElement(time);
rowData.addElement(tmp);


}
}



}

splfList.close();

}

catch( ExtendedIllegalStateException ex )
{
System.out.println(" The list was closed before it completed!");
}

catch( Exception e )
{
// ...handle any other exceptions...
e.printStackTrace();
}


return rowData;
//return arrRowData;
}

// This is where the foreground thread waits to be awaken by the
// the background thread when the list is updated or it ends.
private synchronized void waitForWakeUp()
throws InterruptedException
{
// don''t go back to sleep if the listener says the list is done
if (!fListCompleted)
{
wait();
}
}

// The following methods implement the PrintObjectListListener interface

// This method is invoked when the list is closed.
public void listClosed(PrintObjectListEvent event)
{
System.out.println("*****The list was closed*****");
fListClosed = true;
synchronized(this)
{
// Set flag to indicate that the list has
// completed and wake up foreground thread.
fListCompleted = true;
notifyAll();
}
}

// This method is invoked when the list is completed.
public void listCompleted(PrintObjectListEvent event)
{
System.out.println("*****The list has completed*****");
synchronized (this)
{
// Set flag to indicate that the list has
// completed and wake up foreground thread.
fListCompleted = true;
notifyAll();
}
}

// This method is invoked if an error occurs while retrieving
// the list.
public void listErrorOccurred(PrintObjectListEvent event)
{
System.out.println("*****The list had an error*****");
fListError = true;
listException = event.getException();
synchronized(this)
{
// Set flag to indicate that the list has
// completed and wake up foreground thread.
fListCompleted = true;
notifyAll();
}
}

// This method is invoked when the list is opened.
public void listOpened(PrintObjectListEvent event)
{
System.out.println("*****The list was opened*****");
listObjectCount = 0;
}

// This method is invoked when an object is added to the list.
public void listObjectAdded(PrintObjectListEvent event)
{
// every 25 objects we'll wake up the foreground
// thread to get the latest objects...
if( (++listObjectCount % 1) == 0 )
{
//System.out.println("*****1 more objects added to the list*****");
synchronized (this)
{
// wake up foreground thread
notifyAll();
}
}
}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 18 2003
Added on Jun 20 2003
1 comment
552 views