Talend tJava component allows us to write our own custom Java code. In this example, we use this Talend tJava component and writes a simple print line java statements.
Talend tJava example
Drag and drop the Talend tJava component from palette to job design. As you can see from the Component tab, it has the default java code that declares a string variable and assigned bar to it.
Let me write a simple println statement with a welcome message, and run the Talend Java job.
From the below screenshot, you can see the message.
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 performed.
To get those results, we are using 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.