Skip to main content Skip to complementary content

Creating a drop-down list

This Job shows how to use a MySQL database table to create a drop-down list in a Talend Job.

This Job uses the following components:

  • a tJava component to prepare the drop-down list and store the value selected by the user at runtime in the context variable.
  • a tMysqlInput component to query the people information from the employee table.
  • a tLogRow component to print the result on the console.

Procedure

  1. In Talend Studio, create a new Job named DropDownListExample.
  2. Click the Context view and define a context variable of String type, call it name. This variable stores the drop-down value selected by the user at runtime.
  3. Drop a tJava and a tMysqlInput component from the Palette onto the design workspace. Connect the tJava and the tMysqlInput component with a Trigger > OnSubjobOk link.
  4. Drop a tLogRow component and connect it with a Row > Main link to tMysqlInput.
  5. Double-click tJava and:
    1. add the following piece of Java code to prepare the drop-down list:
      String[] nameStrings = { "Elisa", "Nicolas", "Cedric", "Rabbit", "Mike","Sabrina","Stephane","Jim","John"};
                                  JFrame frame = new JFrame("Input Dialog Example");
                                  String returnValue = (String) JOptionPane.showInputDialog(frame,
                                  "Select the name you want to query?","Employee Information",JOptionPane.QUESTION_MESSAGE,null,nameStrings,nameStrings[0]);
                                  context.name=returnValue; //store the value to the context variable
    2. Store the value selected by the user at runtime in the context variable,
    3. Click Advanced settings and import the full path of the class used in this Job.
  6. Configure the tMysqlInput to query the people information from the employee table:
    1. in the Query box, use a context variable to select the information of the employee chosen by the user at runtime,
      "select * from employee where name='"+context.name+"'"
    2. in the Edit Schema dialog box, define the data structure of the employee table.
  7. Double-click tLogRow and configure its settings to print the results on Talend Studio.
  8. Execute the Job, and select one of the names from the drop-down list when prompted.
  9. For example, select Stephane from the list. The information is queried from the table and printed on the console.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!