Component family |
Cloud/AmazonRDS/MySQL |
|
Function |
Opens a connection to the database for a current |
|
Purpose |
This component is used to open a connection to the specified database that can then be reused in the subsequent subjob or subjobs. |
|
Basic settings |
Property type |
Either Built-in or Repository. Since version 5.6, both the Built-In mode and the Repository mode are |
|
|
Built-in: No property data stored |
|
|
Repository: Select the repository |
|
DB Version |
MySQL 5 is available. |
|
Host |
Database server IP address. |
|
Port |
Listening port number of DB server. |
|
Database |
Name of the database. |
|
Additional JDBC parameters |
Specify additional connection properties for the DB connection you |
|
Username and |
DB user authentication data. To enter the password, click the […] button next to the |
|
Use or register a shared DB Connection |
Select this check box to share your connection or fetch a WarningThis option is incompatible with the Use dynamic job
Shared DB Connection Name: set or |
Advanced settings |
Auto Commit |
Select this check box to commit any changes to the database automatically upon the With this check box selected, you cannot use the corresponding commit component to commit Note that the auto commit function commits each SQL statement as a single transaction |
|
tStatCatcher Statistics |
Select this check box to collect log data at the component |
Global Variables |
ERROR_MESSAGE: the error message generated by the A Flow variable functions during the execution of a component while an After variable To fill up a field or expression with a variable, press Ctrl + For further information about variables, see Talend Studio |
|
Usage |
This component is more commonly used with other tAmazonMysql* |
|
Log4j |
The activity of this component can be logged using the log4j feature. For more information on this feature, see Talend Studio User For more information on the log4j logging levels, see the Apache documentation at http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html. |
|
Limitation |
n/a |
The following Job is dedicated to advanced database users, who want to carry out
multiple table insertions using a parent table id to feed a child table. As a
prerequisite to this Job, follow the steps described below to create the relevant tables
using an engine such as innodb.
-
In a command line editor, connect to your Mysql server. Once connected to
the relevant database, type in the following command to create the parent
table: create table f1090_mum(id int not null auto_increment, name
varchar(10), primary key(id)) engine=innodb. -
Then create the second table: create table baby (id_baby int not null,
years int) engine=innodb.Back into Talend Studio, the
Job requires seven components including tAmazonMysqlConnection and tAmazonMysqlCommit. -
Drag and drop the following components from the Palette: tFileList,
tFileInputDelimited, tMap, tAmazonMysqlOutput (x2). -
Connect the tFileList component to the
input file component using an Iterate link
as the name of the file to be processed will be dynamically filled in from
the tFileList directory using a global
variable. -
Connect the tFileInputDelimited
component to the tMap and dispatch the flow
between the two output AmazonMysql DB components. Use a Row link for each for these connections
representing the main data flow. -
Set the tFileList component properties,
such as the directory name where files will be fetched from. -
Add a tAmazonMysqlConnection component
and connect it to the starter component of this job, in this example, the
tFileList component using an OnComponentOk link to define the execution
order.
In the tAmazonMysqlConnection Component view,
set the connection details manually or fetch them from the Repository if you
centrally stored them as a Metadata DB connection entry. For more information
about Metadata, see Talend Studio User
Guide.
-
On the tFileInputDelimited component’s
Basic settings panel, press Ctrl+Space bar to access the variable list. Set
the File Name field to the global variable:
tFileList_1.CURRENT_FILEPATH -
Set the rest of the fields as usual, defining the row and field
separators according to your file structure. Then set the schema manually
through the Edit schema feature or select
the schema from the Repository. Make sure the data type is correctly set, in
accordance with the nature of the data processed.
-
In the tMap Output area, add two output
tables, one called mum for the parent table, the second called baby, for the
child table. -
Drag the Name column from the Input area, and drop it to the mum table. Drag the
Years column from the Input area and drop it to the baby table.Make sure the mum table is on the top of the baby table as the order is
determining for the flow sequence hence the DB insert to perform
correctly. -
Then connect the output row link to distribute correctly the flow to the
relevant DB output component.
-
In each of the tAmazonMysqlOutput
components’ Basic settings panel, select
the Use an existing connection check box to
retrieve the tAmazonMysqlConnection
details. -
Set the Table name making sure it
corresponds to the correct table, in this example either
f1090_mum or
f1090_baby.There is no action on the table as they are already created.
-
Select Insert as Action on data for both output components. Click on
Sync columns to retrieve the schema set
in the tMap. -
Go to the Advanced settings panel of each
of the tAmazonMysqlOutput components.
Notice that the Commit every field will get
overridden by the tAmazonMysqlCommit. -
In the Additional columns area of the DB
output component corresponding to the child table
(f1090_baby), set the id_baby column so that it
reuses the id from the parent table. In the SQL
expression field type in: ‘(Select Last_Insert_id())’.The position is Before and the Reference column is years.
-
Add the tAmazonMysqlCommit component to
the design workspace and connect it from the tFileList component using a OnComponentOk connection in order for the Job to terminate
with the transaction commit. -
On the tAmazonMysqlCommit
Component view, select in the list the
connection to be used.