Setting a database value to context variable in talend

不羁岁月 提交于 2019-12-01 12:31:35

问题


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 ??


回答1:


  1. Select distinct username from table.
  2. Use tFlowToIterate to iterate on each of the usernames. (connect table component to this component using main link)
  3. Use Iterate link to connect to tJava component.
  4. 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.
  5. Connect tJava to a table component using 'OnComponentOk' to Select data from table based on the where condition: username='"+context variable+"'
  6. Write data into file. Give filename as "<path>\"+context.username.



回答2:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!