Sent a value from a tJava component to a tMap - talend

I want to retrieve the value of a tJava component in a tMap component.
I made my program, and returns a row.ma_value
I create my schema as built-in.
I try to connect it to my tMap component but it doesn't give me any connection.

tJava is not to be used as a flow component. Use tJavaRow instead to pass rows to the next component. With tJavaRow you get 2 variables: input_row to access input flow columns, and output_row to access outgoing flow columns.
If you need tJavaRow to be the first component of the subjob, use tJavaFlex instead.

Related

Dynamic filter rows in Talend

Is it possible to get values from a Excel file and use them to filter rows in Talend?
For example:
I have an Excel file with account numbers list.
In Talend, I have a query in a tDBInput linked to a tMap, that is linked to a tFilter. This filter is based on Excel columns values with the accounts list.
Or if I can use the account list in the where clause in tDBInput. The problem is that the account list can change anytime.
Thanks a lot.
There are multiple ways to proceed :
Link your tDBInput to tMap as the main flow, and your excelInput as the lookup. Make the join between the two flow in tMap as an inner join : this way you can filter main data with data coming from excel. The inconvenient is that you will read all data from DBInput and filter after that, which is less efficient.
You can also make it through two subjobs :
First subjob : tFileInputExcel -> tJavaRow . Push your list of accounts to a String in a context variable to construct your "where" query. (you can also use a tAggregateRow with 'list' mode to build a list )
Second subjob : use this constructed context variable as filter in your DBInput query. This way you'll read only valuable data in this component.

talend open studio create tmap

I want to select certain columns from 2 tables by coding the appropriate SQL code in the "query" zone of my tMySQLInput component. Then I've been told to use a "tMap" component in order to map each column from my tMySQLInput component to my tMySQLOutput component.
Is this the correct way to to do what I need to do : Take information (SELECT ...) from 2 tables and then insert them into another 3 rd table?
Inorder to insert data from 2 tables (source) into another table(target), it is necessary to use tmap component.
1.tMysqlinput(with query) and check the edit schema section for appropriate values you wish to send to the output/target
2.tMap component map all the necessary columns from source to target
3.tMysqlOutput check the edit schema section for appropriate columns that you wish to see in your target.

Talend how to connect the tfileInputDelimited to tjava and tLibraryLoad and get the changes reflect in tfileOutputDelimited

tfileInputDelimited has the 3 fields
id name text
tfileInputDelimited --iterate---> tjava --row-> tfileOutputDelimited
how can I get the the text field in tjava so that the changes that done in tjava can be reflected in outputfile.
Use tJavaRow component instead of tJava
An alternative to tJavaRow is to use tMap in the same manner than #xto specified.

Use an existing database connexion in a tJava component

I'm looking for a way to Call an existing database connxion in a tJava Component.
I have created a new BDD connexion in the JAVA Bloc , but this new connexion not permit me to use the data insert with the tMySqlConnexion Component because the first connexion do his commit at the end of the job.
I need to use in the JAVA bloc the same connexion using in the tMySqlConnexion.
Thank you for you help !
The tMysqlConnection component stores the connection in the job's globalMap. You can retrieve it from there and use it in your tJava component, like so:
java.sql.Connection c = (java.sql.Connection)globalMap.get("conn_tMysqlConnection_1");
This assumes that your tMysqlConnection has the unique name tMysqlConnection_1; change this to the actual name used in your job.

Setting a database value to context variable in talend

I have a job that flows like this.
tAccessDatabse_1 ---> tFileOutputXML_1.
Now, my database has a schema, with usename and userid. My task to create/send data from the database to xml file, file name with username i.e, one file has to create for every user with his/her name.
I tried like creating a conetxt varible but how can i set username to that context variable from the database ??
Select distinct username from table.
Use tFlowToIterate to iterate on each of the usernames. (connect table component to this component using main link)
Use Iterate link to connect to tJava component.
Assign the username to context variable using tjava component. For eg. if output row from the table component is row1, then context.username=row1.username.
Connect tJava to a table component using 'OnComponentOk' to Select data from table based on the where condition: username='"+context variable+"'
Write data into file. Give filename as "<path>\"+context.username.
tYOURDBInput -> [row1] -> tFlowToItterate -> [itterate] -> tJava -> "globalMap.put("DESC", (String)row1.column);"
If you have just the one line then pick it up elsewhere via
(String) globalMap.get("DESC")
I used this setup to retrieve passwords to foreign systems stored in a table which are to be refreshed regurarily. This prevents code rebuilds everytime the password changes. Do protect your table naturally.