Assigning a database value to a context variable in Talend

0 votes

In my database table, I have 2 columns containing username and userId. Now I want to send this data to an XML file such that a new XML file is created per user based on the username. In order to do so, I am trying to set a value from my database table to the context variable. My job looks something like following:

tAccessDatabase_1 ---> tFileOutputXML_1

But its not working out. Can someone suggest me a solution?

Apr 5, 2018 in Talend by misc.edu04
• 1,450 points
5,758 views

2 answers to this question.

0 votes

You can try following the below steps:

1. Select a distinct username from the database table.

2. Now, to iterate on each of the usernames add a tFlowToIterate component.

3. By using an iterate link, connect a tJava component.

4. Then you can assign the username to context variable by using tJava component. Then type: context.username=row1.username.

5. Now, connect the tJava component to a table component by using 'OnComponentOk' trigger to select data from the table based on the where condition: username='"+context variable+"'.

6. Finally, you can write data into a file. Provide the filename as: "<path>\"+context.username.

Hope this helps.

To learn more about Talend' it's recommended to join Talend training today.

Thanks.

answered Apr 5, 2018 by code.reaper12
• 3,500 points
0 votes

Hi,
You can do one thing -
1) In tDBinput_1 use below query -
select KeyValue AS DBKeyValue
from KeyTable
where KeyName='MaxIdValue'


2) Put DBKeyValue in the schema of tDBInput.

3) Add Context variable in context section. Consider context name is : MaxKeyValue
3) After that use tJavaRow and use below code -
context.MaxKeyValue = input_row.DBKeyValue
Don't forget to add this context variable in the context section.

Best Regards,
Siddharth Poddar

poddarsiddharth1990@gmail.com

answered May 18, 2019 by Archana
• 140 points

Related Questions In Talend

0 votes
1 answer

Assigning Context Variable from the database value

I think if you want to link ...READ MORE

answered Apr 19, 2018 in Talend by geek.erkami
• 2,680 points
2,363 views
0 votes
1 answer

Naming the output based on a column value in Talend

You can try to solve this problem ...READ MORE

answered Apr 19, 2018 in Talend by 93.lynn
• 1,600 points
2,279 views
0 votes
0 answers

How can I use talend to extract data from Oracle and import the data into a MSSQL database?

We currently have around 100 Oracle tables ...READ MORE

Nov 4, 2020 in Talend by umesh
• 150 points
2,157 views
0 votes
1 answer

Using tHiveRow to execute multiple Hive queries in Talend

In order to execute multiple queries, you ...READ MORE

answered Apr 14, 2018 in Talend by misc.edu04
• 1,450 points
3,518 views
0 votes
1 answer

tWaitForFile component insufficiency in Talend

Regarding your first issue, tWaitForFile component provides ...READ MORE

answered Apr 11, 2018 in Talend by geek.erkami
• 2,680 points
2,148 views
0 votes
1 answer
+1 vote
1 answer
0 votes
2 answers

Closed loop in Talend

Hi, Talend specifies that tUnite cannot be ...READ MORE

answered Aug 23, 2019 in Talend by vinceall
1,867 views
0 votes
1 answer

How to load a set of files into database using Talend

Using tFileList component,  you can read all the files present ...READ MORE

answered Apr 17, 2018 in Talend by code.reaper12
• 3,500 points
5,668 views
0 votes
1 answer

How to generate multiple rows from a single row in Talend?

I think using tJavaFlex, tMap and tFlowToIterate ...READ MORE

answered Apr 18, 2018 in Talend by code.reaper12
• 3,500 points
7,252 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP