JT400默认使用QUSER,调用RPG程序时如何切换为当前用户?
Great questions—let’s tackle them one by one to get your JT400 and RPG setup working as expected:
Absolutely. QUSER is only used as the default when you don’t provide explicit authentication credentials during your IBM i connection setup. Here are the most common ways to switch to a different user:
- Explicit credentials in code: When instantiating the
AS400object, pass your target username and password directly:AS400 as400 = new AS400("your-ibm-i-system", "target-username", "target-password"); - JDBC connection configuration: If you’re using JT400 for JDBC connections, include the user and password in your JDBC URL or connection properties:
jdbc:as400://your-ibm-i-system;user=target-username;password=target-password - System properties: Set global JT400 properties before initializing your connection (useful if you want to apply this across your app):
System.setProperty("com.ibm.as400.access.User", "target-username"); System.setProperty("com.ibm.as400.access.Password", "target-password");
The root cause here is that your Java app is still connecting to IBM i using QUSER’s identity—so the RPG program runs in a job owned by QUSER, which is why the PSDS picks up that user ID. To fix this:
- Use the correct connection credentials: First, update your JT400 connection to use the actual current user’s credentials (follow the steps from the first question). This ensures the IBM i job associated with your connection runs under that user, not QUSER.
- Verify your RPG PSDS setup: Make sure your PSDS is correctly referencing the user ID field. The standard PSDS has the job’s user ID starting at position 129, with a length of 10 characters. Example RPGLE code:
Dcl-Ds Psds Qualified; JobUserId Char(10) Pos(129); End-Ds; - Integrated authentication (if applicable): If you’re on a Windows machine and want to use the logged-in OS user’s credentials for IBM i access, enable default user authentication:
This will pass your Windows user’s credentials to IBM i, and the RPG job will run under that user—so the PSDS will return the correct ID.AS400 as400 = new AS400("your-ibm-i-system"); as400.setUseDefaultUser(true);
A quick best practice: Avoid using QUSER for application connections unless strictly necessary. QUSER has broad privileges, so using a least-privilege user for your app connections is better for security.
内容的提问来源于stack exchange,提问作者Bashdi

