Well, Ideally i should have covered this topic in my previous blog on “Java and Pentaho Kettle | Executing a kettle File using Java“, but somehow i managed to miss this out. So in case you haven’t read the above blog, i suggest you have a look at-least once before you continue with this topic.
Passing Parameter is one of the basic and important feature of Pentaho Data Integration/Kettle. You have the ability to dynamically pass the meta-data to any pentaho transformation/jobs. In PDI, we use “Parameters” section to define all the parameters name and pass on the value to the respective jobs. Check the image below:

We can also do the same when we would be calling a Pentaho Job/Transformation using a java code. I will extend my code from the above blog link and will add on to it.
Passing Parameters to Transformation (.KTR)
The code here is pretty simple. You just need to define the Parameters to the “setParameterValue(key, value)” method like below:
trans.setParameterValue("PARAM_ID", "1");
trans.setParameterValue("PARAM_NAME", "Rishu");
Here: PARAM_ID and PARAM_NAME are the two parameter names which i want to pass to my .ktr file and their corresponding values being “1” and “Rishu”. Whereas, trans is the object of Trans class, which is used to get metadata of a transformation.
A complete code snippet is as below:
try {
KettleEnvironment.init();
TransMeta metadata=new TransMeta(file);
Trans trans=new Trans(metadata);
/* Setting the Parameter Values
* @PARAM_ID : Parameter Name
* @PARAM_NAME : Parameter Name (second parameter)
*/
trans.setParameterValue("PARAM_ID", "1");
trans.setParameterValue("PARAM_NAME", "Rishu");
/* Executing or starting a .ktr file */
trans.execute(null);
trans.waitUntilFinished();
if(trans.getErrors()>0){
System.out.println("Error Executing Transformation");
}
} catch (KettleException e) {
e.printStackTrace();
}
Passing Parameters to Jobs (.KJB)
Subscribe to continue reading
Subscribe to get access to the rest of this post and other subscriber-only content.


15 responses to “Passing Parameters to Kettle Using Java | Pentaho Data Integration”