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 4, 2018 in Talend by misc.edu04
• 1,380 points
474 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.

answered Apr 4, 2018 by code.reaper12
• 3,450 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 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,320 points
168 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,560 points
289 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,380 points
712 views
0 votes
1 answer

Creating a New Project in Talend Open Studio

Before you switch over to a new ...READ MORE

answered Apr 18, 2018 in Talend by misc.edu04
• 1,380 points
206 views
0 votes
1 answer

tWaitForFile component insufficiency in Talend

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

answered Apr 10, 2018 in Talend by geek.erkami
• 2,320 points
285 views
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

Closed loop in Talend

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

answered Aug 22 in Talend by vinceall
308 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 16, 2018 in Talend by code.reaper12
• 3,450 points
551 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,450 points
1,214 views