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
In Talend Studio,
create a new Job named DropDownListExample.
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.
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.
Drop a tLogRow component and connect it with a
Row > Main link to
tMysqlInput.
Double-click tJava and:
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
Store the value selected by the user at runtime in the context
variable,
Click Advanced settings and import the full path
of the class used in this Job.
Configure the tMysqlInput to query the people
information from the employee table:
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+"'"
in the Edit Schema dialog box, define the data
structure of the employee table.
Double-click tLogRow and configure its settings to print the
results on Talend Studio.
Execute the Job, and select one of the names from the drop-down list when
prompted.
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!