### Example Toolbox Trace Output Source: https://github.com/ibm/jtopen/blob/main/docs/usage/logging/LOGGING.md This is an example of the output generated by the JTopen toolbox when tracing is enabled. It shows the initialization process and system property checks. ```pascal Toolbox for Java - Open Source Software, JTOpen 6.2, codebase 5761-JC1 V6R1M0.4 Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:592 CDT 2008 Getting system property: 'com.ibm.as400.access.Trace.enabled' Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:592 CDT 2008 Value found in system properties: 'null' Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 Loading Properties class: 'com.ibm.as400.access.Properties' Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 Unable to load class: com.ibm.as400.access.Properties Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 Loading jt400.properties file: 'com.ibm.as400.access.jt400.properties' Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 Trying with Class.getResourceAsStream(): false Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 Trying with ClassLoader.getSystemResourceAsStream(): false Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 Load of jt400.properties failed. Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 Value found in jt400.properties file: 'null' Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 Value not found. Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 as400: Properties (9826960) : access = "all". Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 as400: Properties (9826960) : block size = "32". Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 as400: Properties (9826960) : block criteria = "2". Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 as400: Properties (9826960) : date format = "". Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 as400: Properties (9826960) : date separator = "". Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 as400: Properties (9826960) : decimal separator = "". Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 as400: Properties (9826960) : errors = "basic". Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 as400: Properties (9826960) : extended dynamic = "false". Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 as400: Properties (9826960) : libraries = "". Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 as400: Properties (9826960) : naming = "sql". Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 as400: Properties (9826960) : package = "". Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 as400: Properties (9826960) : package add = "true". Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 as400: Properties (9826960) : package cache = "false". Thread[AWT-EventQueue-0,6,main] Wed May 28 14:58:24:602 CDT 2008 as400: Properties (9826960) : package clear = "false". ``` -------------------------------- ### Example JDBC Connection String with Tracing Enabled Source: https://github.com/ibm/jtopen/blob/main/docs/usage/logging/LOGGING.md This example demonstrates how to enable toolbox tracing, JDBC tracing, and server-side traces using a single JDBC connection string. ```sql "jdbc:as400://mysystem;toolbox trace=all;trace=true;server trace=126;" ``` -------------------------------- ### Main Method: AS400 Connection and Spooled File Setup Source: https://github.com/ibm/jtopen/blob/main/src/main/javadoc/com/ibm/as400/access/doc-files/LDRWExample.html Establishes a connection to the AS/400 system and configures the output queue and print parameters for a line data spooled file. Ensure the AS400 object is properly initialized with system, user, and password. ```Java // create an instance of the system system_ = new AS400("SYSTEMA", "JOE", "PGMR"); // create a ccsid ccsid_ = system_.getCcsid(); // create output queue and specify spooled file data to be *LINE OutputQueue outQ = new OutputQueue(system_, "/QSYS.LIB/QUSRSYS.LIB/LDRW.OUTQ"); PrintParameterList parms = new PrintParameterList(); parms.setParameter(PrintObject.ATTR_PRTDEVTYPE, "*LINE"); parms.setParameter(PrintObject.ATTR_PAGDFN,"/QSYS.LIB.QUSRSYS.LIB/LDRW.PAGDFN"); parms.setParameter(PrintObject.ATTR_CONVERT_LINEDATA,"*YES"); ``` -------------------------------- ### Set Trace Properties via Domain Script Source: https://github.com/ibm/jtopen/blob/main/docs/usage/logging/WILDFLY_LOGGING.md Specify a properties file to configure trace settings when starting WildFly in domain mode. ```bash $JBOSS_HOME/bin/domain.sh --properties=/some/location/jboss.properties ``` -------------------------------- ### Connect to IBM i and Query Data using JDBC Source: https://github.com/ibm/jtopen/blob/main/docs/usage/examples/JDBC.md This example demonstrates how to establish a JDBC connection to an IBM i database, execute a SQL query, and process the results. Ensure the jt400.jar is in your classpath and replace placeholder credentials with your actual database details. ```java import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Properties; public class AS400JDBCExample { public static void main(String[] args) { String url = "jdbc:as400://pub400.com"; Properties props = new Properties(); props.put("user", "user"); props.put("password", "password"); props.put("prompt", "true"); // login form if needed // add more properties here try (Connection conn = DriverManager.getConnection(url, props)) { System.out.println("Connected to IBM i database successfully!"); String sql = "SELECT SERVICE_NAME, EXAMPLE FROM QSYS2.SERVICES_INFO where SERVICE_CATEGORY = 'PRODUCT'"; try (PreparedStatement stmt = conn.prepareStatement(sql); ResultSet rs = stmt.executeQuery()) { while (rs.next()) { System.out.println("Service: " + rs.getString("SERVICE_NAME")); System.out.println("Example SQL: "); System.out.println(rs.getString("EXAMPLE")); System.out.println(); System.out.println(); } } System.out.println("Connection closed."); } catch (SQLException e) { System.err.println("SQL Exception: " + e.getMessage()); } } } ``` -------------------------------- ### Set Trace Properties via Standalone Script Source: https://github.com/ibm/jtopen/blob/main/docs/usage/logging/WILDFLY_LOGGING.md Configure trace categories and output files directly when starting WildFly in standalone mode using command-line arguments. ```bash $JBOSS_HOME/bin/standalone.sh -Dcom.ibm.as400.access.Trace.category=all \ -Dcom.ibm.as400.access.Trace.file=/tmp/toolbox_trace.txt ``` -------------------------------- ### Access AS400 System Value Source: https://github.com/ibm/jtopen/blob/main/docs/usage/BASIC_USAGE.md Use an established AS400 connection object to retrieve the value of a system value. This example shows how to get the 'QHSTLOGSIZ' system value. ```java AS400 conn = new AS400(); SystemValue mySysVal = new SystemValue(conn, "QHSTLOGSIZ"); Object value = mySysVal.getValue(); ``` -------------------------------- ### Get System Properties Source: https://github.com/ibm/jtopen/blob/main/src/main/javadoc/com/ibm/as400/access/doc-files/SystemPropertiesSample2.html Retrieves and displays the system name and version. Ensure the IBM Toolbox for Java classes are in your classpath. ```Java import com.ibm.as400.access.*; public class SystemPropertiesSample2 { public static void main(String[] args) { // Replace "your_system_name" with the actual AS/400 system name String systemName = "your_system_name"; try { // Create a ConnectionKey object ConnectionKey key = new ConnectionKey(systemName); // Create a System object AS400 system = new AS400(key); // Get the system name String name = system.getSystemName(); System.out.println("System name: " + name); // Get the system version String version = system.getSystemVersion(); System.out.println("System version: " + version); // Disconnect from the system system.disconnectService(AS400.COMMAND); } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### Initialize AS400 Connection and Define Record Format Source: https://github.com/ibm/jtopen/blob/main/src/main/javadoc/com/ibm/as400/access/doc-files/RLReadFileExample.html This snippet shows how to establish a connection to an AS/400 system and define the structure of records within a file using various field description classes. It is essential for preparing to read data from a specific file. ```Java import java.io.*; import java.util.*; import java.math.*; import com.ibm.as400.access.*; public class RLReadFile extends Object { public static void main(String[] parameters) { String system = ""; // Continue only if a system name was specified. if (parameters.length >= 1) { try { // Assume the first parameter is the system name. system = parameters[0]; // Create an AS400 object for the system that has the file. AS400 as400 = new AS400(system); // Create a record description for the file. The file is QCUSTCDT // in library QIWS. ZonedDecimalFieldDescription customerNumber = new ZonedDecimalFieldDescription(new AS400ZonedDecimal(6,0), "CUSNUM"); CharacterFieldDescription lastName = new CharacterFieldDescription(new AS400Text(8, as400), "LSTNAM"); CharacterFieldDescription initials = new CharacterFieldDescription(new AS400Text(3, as400), "INIT"); CharacterFieldDescription street = new CharacterFieldDescription(new AS400Text(13, as400), "STREET"); CharacterFieldDescription city = new CharacterFieldDescription(new AS400Text(6, as400), "CITY"); CharacterFieldDescription state = new CharacterFieldDescription(new AS400Text(2, as400), "STATE"); ZonedDecimalFieldDescription zipCode = new ZonedDecimalFieldDescription(new AS400ZonedDecimal(5,0), "ZIPCOD"); ZonedDecimalFieldDescription creditLimit = new ZonedDecimalFieldDescription(new AS400ZonedDecimal(4,0), "CDTLMT"); ZonedDecimalFieldDescription chargeCode = new ZonedDecimalFieldDescription(new AS400ZonedDecimal(1,0), "CHGCOD"); ZonedDecimalFieldDescription balanceDue = new ZonedDecimalFieldDescription(new AS400ZonedDecimal(6,2), "BALDUE"); ZonedDecimalFieldDescription creditDue = new ZonedDecimalFieldDescription(new AS400ZonedDecimal(6,2), "CDTDUE"); // The record format name should be specified for a DDM file. // In the case of the QCUSTCDT file, its record format is called CUSREC. RecordFormat qcustcdt = new RecordFormat("CUSREC"); qcustcdt.addFieldDescription(customerNumber); qcustcdt.addFieldDescription(lastName); qcustcdt.addFieldDescription(initials); qcustcdt.addFieldDescription(street); qcustcdt.addFieldDescription(city); qcustcdt.addFieldDescription(state); qcustcdt.addFieldDescription(zipCode); qcustcdt.addFieldDescription(creditLimit); qcustcdt.addFieldDescription(chargeCode); qcustcdt.addFieldDescription(balanceDue); qcustcdt.addFieldDescription(creditDue); // Create the sequential file object that represents the // file on the system. We use a QSYSObjectPathName object // to get the name of the file into the correct format. QSYSObjectPathName fileName = new QSYSObjectPathName("QIWS", "QCUSTCDT", "FILE"); SequentialFile file = new SequentialFile(as400, fileName.getPath()); // Let the file object know the format of the records. file.setRecordFormat(qcustcdt); // Open the file for read-only access. Specify a blocking ``` -------------------------------- ### Initialize Record Format for Line Data Source: https://github.com/ibm/jtopen/blob/main/src/main/javadoc/com/ibm/as400/access/doc-files/LDRWExample.html Sets up a record format with descriptions for various fields, including customer number, name, address, and financial details. It configures layout attributes like length and alignment for each field. ```Java import com.ibm.as400.access.*; import java.io.*; import java.math.BigDecimal; public class TestA { //Private private static int ccsid_ = -1; // local ccsid variable private static AS400 system_ = null; // the system private static SequentialFile file_ = null; // the file /** * Create the record field descriptions and record format. **/ public static RecordFormat initializeRecordFormat() { // Create the record format. RecordFormat qcustcdt = new RecordFormat(); // Create record field descriptions for the record format. ZonedDecimalFieldDescription customerNumber = new ZonedDecimalFieldDescription(new AS400ZonedDecimal(6,0), "CUSNUM"); CharacterFieldDescription lastName = new CharacterFieldDescription(new AS400Text(8, ccsid_, system_), "LSTNAM"); CharacterFieldDescription initials = new CharacterFieldDescription(new AS400Text(3, ccsid_, system_), "INIT"); CharacterFieldDescription street = new CharacterFieldDescription(new AS400Text(13, ccsid_, system_), "STREET"); CharacterFieldDescription city = new CharacterFieldDescription(new AS400Text(6, ccsid_, system_), "CITY"); CharacterFieldDescription state = new CharacterFieldDescription(new AS400Text(2, ccsid_, system_), "STATE"); ZonedDecimalFieldDescription zipCode = new ZonedDecimalFieldDescription(new AS400ZonedDecimal(5,0), "ZIPCOD"); ZonedDecimalFieldDescription creditLimit = new ZonedDecimalFieldDescription(new AS400ZonedDecimal(4,0), "CDTLMT"); ZonedDecimalFieldDescription chargeCode = new ZonedDecimalFieldDescription(new AS400ZonedDecimal(1,0), "CHGCOD"); ZonedDecimalFieldDescription balanceDue = new ZonedDecimalFieldDescription(new AS400ZonedDecimal(6,2), "BALDUE"); ZonedDecimalFieldDescription creditDue = new ZonedDecimalFieldDescription(new AS400ZonedDecimal(6,2), "CDTDUE"); // assign constants from FieldDescription class int justLeft = FieldDescription.ALIGN_LEFT; int justRight = FieldDescription.ALIGN_RIGHT; // set the length and alignment attributes for writing the fields // The length indicates how many characters the field is, and // justification indicates where in the layout field the data // should be placed. customerNumber.setLayoutAttributes(10,justLeft); lastName.setLayoutAttributes(10,justLeft); initials.setLayoutAttributes(4,justLeft); street.setLayoutAttributes(15,justLeft); city.setLayoutAttributes(10,justLeft); state.setLayoutAttributes(3,justLeft); zipCode.setLayoutAttributes(5,justLeft); creditLimit.setLayoutAttributes(10,justRight); chargeCode.setLayoutAttributes(3,justRight); balanceDue.setLayoutAttributes(10,justRight); creditDue.setLayoutAttributes(10,justRight); // set the record format ID String d = "CUSTRECID"; qcustcdt.setRecordFormatID(d); // if this were a variable field length record, // we would set the type and delimiter accordingly. We // also would not have needed to specify layoutLength and // layoutAlignment values. // qcustcdt.setRecordFormatType(RecordFormat.VARIABLE_LAYOUT_LENGTH); // qcustcdt.setDelimiter(';'); // set the record type to fixed field length qcustcdt.setRecordFormatType(RecordFormat.FIXED_LAYOUT_LENGTH); // add the field descriptions to the record format. qcustcdt.addFieldDescription(customerNumber); qcustcdt.addFieldDescription(lastName); qcustcdt.addFieldDescription(initials); ``` -------------------------------- ### Configure Tracing for RPG Invocated JVM Source: https://github.com/ibm/jtopen/blob/main/docs/usage/logging/LOGGING.md For Java methods called from RPG, use the QIBM_RPG_JAVA_PROPERTIES environment variable to set JVM properties. This variable must be set before the JVM starts. ```clle ADDENVVAR ENVVAR(QIBM_RPG_JAVA_PROPERTIES) VALUE('-Dcom.ibm.as400.access.Trace.category=all;-Dcom.ibm.as400.access.Trace.file=/home/mydir/ToolboxTrace.txt;') LEVEL(*SYS) ``` -------------------------------- ### Connect to AS400 with Credentials Source: https://github.com/ibm/jtopen/blob/main/docs/usage/BASIC_USAGE.md Establish a connection to an AS400 system, either locally or remotely, by providing system name, username, and password. The password should be passed as a character array. ```java AS400 conn = new AS400("myibmi.mydomain.net", "MYUSR", "password".toCharArray()); ``` -------------------------------- ### Enable Server Traces for RPG Invocated JVM Source: https://github.com/ibm/jtopen/blob/main/docs/usage/logging/LOGGING.md To enable server traces when calling Java from RPG, include server-specific properties in the QIBM_RPG_JAVA_PROPERTIES environment variable. This example enables JDBC tracing. ```clle ADDENVVAR ENVVAR(QIBM_RPG_JAVA_PROPERTIES) VALUE('-Dcom.ibm.as400.access.Trace.category=all;-Dcom.ibm.as400.access.Trace.file=/home/mydir/ToolboxTrace.txt;-Dcom.ibm.as400.access.ServerTrace.JDBC=126;') LEVEL(*SYS) ``` -------------------------------- ### Configure Server Traces for Data Sources Source: https://github.com/ibm/jtopen/blob/main/docs/usage/logging/WAS_LOGGING.md Add this custom property to toolbox data sources to enable server traces. Requires a server restart. ```properties serverTraceCategories=126 ``` -------------------------------- ### CommandCall - Execute CL Commands Source: https://context7.com/ibm/jtopen/llms.txt Explains how to use the CommandCall class to execute non-interactive CL commands on IBM i. It details how results are returned as AS400Message objects and provides an example of creating and deleting a library. ```APIDOC ## CommandCall - Execute CL Commands `CommandCall` runs any non-interactive IBM i CL command. Results are returned as an array of `AS400Message` objects whether the command succeeds or fails. ### Usage Example ```java import com.ibm.as400.access.*; AS400 sys = new AS400("myibmi.example.com", "JAVAUSER", "s3cr3t".toCharArray()); CommandCall cmd = new CommandCall(sys); try { // Create a library boolean success = cmd.run("CRTLIB LIB(JAVATEST) TEXT('Test library')"); if (!success) { System.out.println("Command FAILED:"); } else { System.out.println("Command succeeded."); } // Always inspect the message list for (AS400Message msg : cmd.getMessageList()) { System.out.printf("[%s] %s%n", msg.getID(), msg.getText()); // Load and display extended help text for errors if (msg.getType() == AS400Message.ESCAPE) { msg.load(); System.out.println(" Help: " + msg.getHelp()); } } // Delete the library cmd.run("DLTLIB LIB(JAVATEST)"); // Mark command as thread-safe (run in the host server job's thread) cmd.setThreadSafe(true); cmd.run("CHGUSRPRF USRPRF(JAVAUSER) JOBD(QGPL/QDFTJOBD)"); } catch (AS400SecurityException | ErrorCompletingRequestException | IOException | InterruptedException e) { e.printStackTrace(); } finally { sys.disconnectService(AS400.COMMAND); } ``` ``` -------------------------------- ### Enable Server Tracing (No Data Sources) Source: https://github.com/ibm/jtopen/blob/main/docs/usage/logging/WAS_LOGGING.md Add this JVM argument to enable server tracing for toolbox/JDBC applications when no data sources are defined in WebSphere. Requires a server restart. ```properties -Dcom.ibm.as400.access.ServerTrace.JDBC=126 ```