如何在tJava组件中调用tMSSqlSP的输出参数值
Hey there! Let's fix this step by step—you're super close since tLogRow already confirms the stored procedure is returning values correctly. The "Is function" checkbox was the wrong path here, so let's walk through the proper ways to access those OUT parameters in tJava.
First, Fix the "Is function" Misconfiguration
That checkbox is exclusively for scalar SQL functions (ones that return a single value), not stored procedures with explicit OUT parameters. Unchecking it will eliminate that compile error immediately.
Method 1: Access via GlobalMap (Simplest for Standalone Values)
This is perfect if you just need to grab the output values directly without passing them through a data stream:
- Configure tMSSqlSP's Output Parameters:
- In your tMSSqlSP settings, scroll to the Output Parameters section.
- Click the
+button twice to add two rows. - For each row, fill in the details to match your stored procedure:
Name Type (match SQL type) Direction Variable nextMsgVARCHAR(example)OUTnextMsgnextDocINT(example)OUTnextDoc
Variablecolumn sets the key Talend will use to store the value in its global context. - Fetch Values in tJava:
Use Talend'sglobalMapobject to retrieve the values, casting them to the correct data type:// Pull the output values from the global context String returnedMsg = (String) globalMap.get("nextMsg"); Integer returnedDoc = (Integer) globalMap.get("nextDoc"); // Use the values as needed System.out.println("Received nextMsg: " + returnedMsg); System.out.println("Received nextDoc: " + returnedDoc);
Method 2: Map to Output Schema (For Stream-Based Processing)
If you want to pass these values along a data flow to other components (like tMap or another tLogRow), map them to an output schema:
- Uncheck "Is function" as before.
- Define the Output Schema:
- Go to the Output Schema tab in tMSSqlSP's settings.
- Add two columns:
nextMsg(matching your SQL parameter's type) andnextDoc(matching its type).
- Link Parameters to Schema Columns:
- Return to the Output Parameters section.
- Use the Mapping dropdown for each parameter to select the corresponding column from your output schema (e.g., map the
nextMsgparameter to thenextMsgschema column).
- Access in tJava:
Now the values are part of the data row, so you can access them directly via therowobject:System.out.println("Row-level nextMsg: " + row.nextMsg); System.out.println("Row-level nextDoc: " + row.nextDoc);
Quick Troubleshooting Tips
- Double-check that Talend's data types exactly match your stored procedure's output types (e.g., use
Longfor SQLBIGINT,BigDecimalforDECIMAL). - If you get a
NullPointerException, confirm theVariablename in Output Parameters matches exactly what you're calling inglobalMap.get(). - Ensure your stored procedure explicitly marks these parameters as
OUT(notINOUTunless you're passing a value in and getting one back).
内容的提问来源于stack exchange,提问作者Tuma

