Search code examples
talendtalend-mdm

Issue in Dynamic Job creation in Talend


I got the requirement like this, Create a single Talend job with reads multiple tables and writes to multiple files dynamically(when we give a tablename via context variable the job should take that table as select * from tablename and writes to file tablename.txt)

My oracle query given in toracle input stage-

"SELECT *  FROM '"+context.Table_Name+"'"

In Context Variable part given as

Table_Name-    String-   checked Prompt for value for dynamic table name

In the metadata definition for Oracle table I gave as

Type="dynamic" db type="varchar2"

Issues Facing:

  1. The context variable is not been identified by the job

    ORA-00903: invalid table name
    Exception in component tOracleInput_1
    java.sql.SQLSyntaxErrorException: ORA-00903: invalid table name
    
    at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:91)
    at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
    

    But when I hard code the tablename, job is running fine

  2. The target file path I gave as

    "C:/Talend/OutputFIles/context.Table_Name.txt"
    

Instead of printing value of context variable, I am getting as context.Table_Name.txt as filename!!!

Please help me on this


Solution

  • Did you try to remove ' around the table name?
    Try this:
    "SELECT * FROM " + context.Table_Name

    Same for filename construction, you should write:
    "C:/Talend/OutputFIles/" + context.Table_Name + ".txt"

    Better, you should have pathname defined by a context variable, giving:
    context.OutputPath + context.Table_Name + ".txt"

    TRF