One Star

[resolved] Calling Talend Job in Java class and pass context variable value

Hi, I have created a Talend Job for reading 2 CSV files and save to 2 database tables based on context variable value. The CSV headers and Table column are same. Only difference is values. So I thought of creating Talend Job.
My CSV files are "inv_ppl1.csv" and "inv_ppl2.csv"
Database tables are "inv_ppl1_flat" and "inv_ppl2_flat"
Context variable is "people" with values "ppl1 and "ppl2" . When I run the Job in Talend it is working fine.

I exported the Job as Zip file as specified in
https://help.talend.com/search/all?query=Calling+a+Talend+Job+from+an+external+Java+application&cont...
I unzipped it. I created a Java project in eclipse. with main method. After that I have added all the JARs to the project. I copied the folder containing properties file. But the directory contains ppl1.prperties and ppl2.properties files only. There is no default.properties file link mentioned in the above link. (I am using TOS for Data Integration... Not Enterprise)
I edited my main method for context variable like in the link
import talenddemo.flatfiletodb_0_1.flatfiletodb; 
public class TalendExample {

/**
* @param args
*/
public static void main(String[] args) {
flatfiletodb talendJob = new flatfiletodb();
int nb_line=2;
String name="ppl2";
String [] context=new String[] {"--context_param nb_line=" nb_line,"--context_param name=" name};
talendJob.runJob(context);
}
}

But it is not working for me. "ppl1" is the default one. so it is reading from first file and saving to its corresponding table. I have passed "ppl2",
But its not working.
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] Calling Talend Job in Java class and pass context variable value

Thanks. It is working now
I removed context_parm nb_line
String name="ppl2";
tring [] context=new String[] {"--context="+name,"--context_param name="+name};
5 REPLIES
Community Manager

Re: [resolved] Calling Talend Job in Java class and pass context variable value

Hi
I think "ppl1" and "ppl2" are two context names in your case, and "ppl1" is the default context, if you want to change the default context, try this code:
String [] context=new String[] {"--context=ppl2 --context_param nb_line="+nb_line,"--context_param name="+name};

Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Calling Talend Job in Java class and pass context variable value

I tried the following
int nb_line=2;
String name="ppl2";
String [] context=new String[] {"--context="+name+" --context_param nb_line="+nb_line,"--context_param name="+name};

And I am getting following error
Could not find the context ppl2 --context_param nb_line=2
/home/sujay/talend/FlatFiles/null/inv_null.csv (No such file or directory)

Both context variable name and its value are smae. For ppl1 its value is ppl1, same like ppl2 also. And what does that nbline means? Why do we need to give that?
EDIT
My main() method is in
src/com/talenddemoj/demojob

And context files are in
src/talenddemojob/flatfiletodb_0_1/contexts
Community Manager

Re: [resolved] Calling Talend Job in Java class and pass context variable value

Hi
nb_line is just a context variable in the tutorial, if you don't have a context variable called nb_line, remove it from your code. A screenshot of the context variables of your job will be helpful for us to understand your problem.
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Calling Talend Job in Java class and pass context variable value

Thanks. It is working now
I removed context_parm nb_line
String name="ppl2";
tring [] context=new String[] {"--context="+name,"--context_param name="+name};
Community Manager

Re: [resolved] Calling Talend Job in Java class and pass context variable value

Thanks. It is working now
I removed context_parm nb_line
String name="ppl2";
tring [] context=new String[] {"--context="+name,"--context_param name="+name};


Cool, glad to see you get it working now.Smiley Wink
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business