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.
来源:https://stackoverflow.com/questions/13468536/setting-a-database-value-to-context-variable-in-talend