You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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:

  1. 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:
      NameType (match SQL type)DirectionVariable
      nextMsgVARCHAR (example)OUTnextMsg
      nextDocINT (example)OUTnextDoc
    The Variable column sets the key Talend will use to store the value in its global context.
  2. Fetch Values in tJava:
    Use Talend's globalMap object 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:

  1. Uncheck "Is function" as before.
  2. Define the Output Schema:
    • Go to the Output Schema tab in tMSSqlSP's settings.
    • Add two columns: nextMsg (matching your SQL parameter's type) and nextDoc (matching its type).
  3. 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 nextMsg parameter to the nextMsg schema column).
  4. Access in tJava:
    Now the values are part of the data row, so you can access them directly via the row object:
    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 Long for SQL BIGINT, BigDecimal for DECIMAL).
  • If you get a NullPointerException, confirm the Variable name in Output Parameters matches exactly what you're calling in globalMap.get().
  • Ensure your stored procedure explicitly marks these parameters as OUT (not INOUT unless you're passing a value in and getting one back).

内容的提问来源于stack exchange,提问作者Tuma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:20:16