Snippet - Referencing Talend SQL Queries And Data Using The tJava Component

In Talend you have the ability to use tJava to insert Java code into your Talend job. Using a tMSSql Input with tJava will allow you to see the actual query being made to the database. The issue that you will run into as a new user is how to reference the Query on the tMSSql component.


Lets say that you have a tMSSql input component called Contacts and you want to see the query that is being used. You will need to add a tJava component and link the two. In the tJava component code field you will need to end up with code the looks as follows:
System.out.println(“My query SQL is as follows:\n”+(String)globalMap.get(“tMSSqlOutput_3_QUERY”)+”\n\n”);

The hardest part to figure out is how to reference the component since it is named “Contact” and you need something similar to “tMSSqlOutput_3_QUERY” The trick it to type in the name of the field in the code box surrounded by quotes and then follow up with a period.

Steps:
1. In the code box type “Contacts”
2. Add the period so that you have “Contacts”.
3. Once you add the period, Talend should show you all of the available components named contacts.
4. Find the one that show the query which will be similar to “Contact”.QUERY
5. Select the appropriate option.

This will turn into a string referencing the required component: (String)globalMap.get(“tMSSqlOutput_3_QUERY”)

Now add the System.out.println method as shown above and run the job.



Author: Josh Sweeney
Last Edited: Jun 08, 2010