Reputation: 121
I am trying to get a list of all of my query/400 queries using the Java library "JT400".
Here is the list represented visually in our terminal application:
I am an accountant by trade, not an AS400 programmer, so I don't know where or how these queries are stored or how the data is retrieved to create the above terminal interface.
I have worked a little with "ObjectList" querying, but don't know which library they would be in (if any). I came across some IBM tool online IBM Tool Doc, which is supposed to provide a command line interface for searching for query/400 objects, but I do not know if we have that installed or if it can do what I need.
Here is my code so far:
ObjectList queryList = new ObjectList(as400, ObjectList.CURRENT_LIBRARY, ObjectList.ALL, ObjectList.ALL);
try {
// Retrieve the list of queries:
queryList.load();
try {
System.out.println(queryList.getLength());
} catch (Exception e) {
e.printStackTrace();
}
Enumeration queries = queryList.getObjects();
for (Enumeration e = queries; e.hasMoreElements();{
System.out.println(e.nextElement());
}
} catch (Exception e){
System.out.println("There was an exception processing the list of queries:");
e.printStackTrace();
}
I finally got this to run without error, but the objects it returns don't look familiar to me and certainly are not the list of query names that I am used to seeing in the terminal.
Upvotes: 1
Views: 210
Reputation: 23823
I think your problems are here
new ObjectList(as400, ObjectList.CURRENT_LIBRARY, ObjectList.ALL, ObjectList.ALL);
objectType
parameter. If all you're interested in is Query/400 queries use "*QRYDFN"
Upvotes: 0
Reputation: 121
I found the answer to my question.
You can generate a list of query/400 queries by user by using the ObjectList class in JT400.
The key is to use "*QRYDFN" in your constructor when defining the object type. In my code, I also specified the specific user in the first string parameter. See constructor info and my code below:
JT400 Docs "ObjectList":
Working code:
public static void ListQueries() throws AS400SecurityException, ObjectDoesNotExistException, IOException, InterruptedException, ErrorCompletingRequestException, RequestNotSupportedException {
AS400 as400 = new AS400();
// Define your object list parameters
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
ObjectList queryList = new ObjectList(as400, as400.getUserId(), ObjectList.ALL, "*QRYDFN");
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Execute your search
queryList.load();
// Create an enumeration containing the returned objects
Enumeration queries = queryList.getObjects();
// Iterate through the objects to print the query names
for (Enumeration e = queries; e.hasMoreElements();)
{System.out.println(e.nextElement());}
}
Resulting list:
Upvotes: 0