Talend tJava

Talend tJava component allows us to write our own custom Java code. In this example, we use this tJava component and write simple print line Java statements.

Talend tJava example

Drag and drop the Talend tJava component from the palette to the job design. As you can see from the Component tab, it has the default Java code that declares a string variable and assigns a bar to it.

Talend tJava Example 1

Let me write a simple println statement with a welcome message and run the Talend tJava job.

Code - System out println statement 2

From the below screenshot, you can see the message.

Click the Run button 3

tJava example 2

In this example, we are using the tReplicate job that we created earlier. We used the OnSubjectOk trigger from the sub job and connected it to the tJava.

Within the Talend tJava Component code, we are printing the 

  • The total number of rows passed from tDBInput.
  • The number of rows inserted into the tReplace table after performing the string Replace.
  • The total number of rows inserted into the Aggregate Row table after the aggregations were performed.
Talend tJava Example 4

To get those results, we use the global variable NB_LINE (gets the number of lines or rows passed) in Java code.

String x = "Total Input Rows = ";
x = x + globalMap.get("tDBInput_1_NB_LINE");
System.out.println(x);

String y = "Total Rows inserted in Talend_Replace Tabel = ";
y = y + globalMap.get("tDBOutput_1_NB_LINE");
System.out.println(y);

String z = "Total Rows inserted in Aggregate Row Tabel = ";
z = z + globalMap.get("tDBOutput_2_NB_LINE");
System.out.println(z);

String r = "Total Rejected Rows by Aggregate Row = ";
r = r + globalMap.get("tDBOutput_2_NB_LINE_REJECTED");
System.out.println(r);

Once you run the Talend Java job, you can see the output.

Talend tJava Example 5