Hitachi Vantara Pentaho Community Forums
Results 1 to 3 of 3

Thread: Passing Variable Values from Java Code

  1. #1
    Join Date
    Nov 2010

    Post Passing Variable Values from Java Code

    I have a chain of Jobs that Synchronize data between a PostGre database and Oracle database. I have used "Set Variable" step in the job to pass the database connection parameters that are common across all the jobs .

    My requirement is to pass these connection details from the Java Code, since changing the jobs for connection settings each time is tedious as the development,testing and production environments are different.

    Following are the steps in my Master Job:

    Start -> Set Variables Step->Job1->Job2->Success Mail

    The set Variables step is as follows:

    Job Entry Name:Set Variables
    Variable Substitution:Yes
    Variable name Value Variable scope type
    PM-HOSTNAME Valid in the current job
    PM-DBNAME DEV-DB1 Valid in the current job
    PM-PORTNUMBER 5432 Valid in the current job

    the DBName can change based on the Environment type.

    I wish to dynamically pass the values to these variables from Java Program. Currently my Java code is as follows:

    public JobResult runInternal(KettleJobs kettleJob) throws KettleException {
    KettleEnvironment.init(); // Initialize Kettle Environment
    EnvUtil.environmentInit(); // Adds the kettle properties to the

    // global system properties.
    JobMeta jobMeta;

    //Pass fileName
    jobMeta = new JobMeta(null, System.getProperty("") + "/" +
    KETTLE_FOLDER + kettleJob.file + ".kjb", null, null);

    // Constructor
    Job job = new Job(null, jobMeta);

    job.setVariable("PM-HOSTNAME", "server1');
    job.setVariable("PM-DBNAME", 'QA-DB1');
    job.setVariable("PM-PORTNUMBER", '5432');


    job.execute(1, job.getResult()); // execute(jobNumber,result)
    if (job.getErrors() > 0) {
    throw new KettleException(buildMessage(job.getJobEntryResults()).toString());
    JobResult jobResult = new JobResult(buildMessage(job.getJobEntryResults()));
    return jobResult;

    As shown above, the default value and the one passed from the Java code for DBName variable are different (DEV-DB1 and QA-DB1). So i expect the variables to be substitued from the java code when i run the job from UI. However, the above code doesnt seem to work.The java code values are not passed and ONLY default values are considered while i run the job.

    Can anyone help?


  2. #2
    Join Date
    Apr 2008


    Follow the workflow of what you're doing...

    You set the variables, and then run the job.
    The first thing that the Job does is... Reset the variables.

    Look at KFF
    It will help you.
    I'm no expert.
    Take my comments at your own risk.

    PDI user since PDI 3.1
    PDI on Windows 7 & Linux

    Please keep in mind (and this may not apply to this thread):
    No forum member is going to do your work for you. We will help you sort out how to do a specific part of the work, as best we can, in the timelines that our work will allow us.
    Signature Updated: 2014-06-30

  3. #3
    Join Date
    Nov 2010


    The issue was fixed by removing the "Set Variable" step from the Jobs. The values passed by the Java code is directly substituted for each transaction.

    Thanks, it was a silly mistake from my end.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.