Component family |
Databases/MSSQL |
|
Function |
tMSSqlConnection opens a |
|
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 Since version 5.6, both the Built-In mode and the Repository mode are |
|
|
Built-in: No property data stored |
|
|
Repository: Select the repository |
|
Host |
Database server IP address. |
|
Port |
Listening port number of DB server. |
|
Schema |
Schema name. |
|
Database |
Name of the database. |
|
Username and |
DB user authentication data. To enter the password, click the […] button next to the |
|
Additional JDBC parameters |
Specify additional connection properties for the DB connection you |
|
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 gather the job processing metadata at a |
Usage |
This component is more commonly used with other tMSSql* |
|
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 |
Due to license incompatibility, one or more JARs required to use this component are not |
The scenario describes a Job that reads the employee data from a text file, inserts
the data into a table of an MSSQL database, then extracts useful data from the table,
and displays the information on the console.
This scenario involves the following components:
-
tMSSqlConnection: establishes a connection to
the MSSQL server. -
tFileInputDelimited: reads the input file,
defines the data structure and sends it to the next component. -
tMSSqlOutput: writes data it receives from
the preceding component into a table of an MSSQL database. -
tMSSqlInput: extracts data from the table
based on an SQL query. -
tLogRow: displays the information it receives
from the preceding component on the console. -
tMSSqlCommit: commits the transaction in the
connected MSSQL server.
-
Drop the following components from the Palette onto the design workspace: tMSSqlConnection, tFileInputDelimited, tMSSqlOutput, tMSSqlInput,
tLogRow, and tMSSqlCommit. -
Connect tMSSqlConnection to tFileInputDelimited using a Trigger > OnSubjobOk
link. -
Do the same to connect tFileInputDelimited to tMSSqlInput and tMSSqlInput
to tMSSqlCommit. -
Connect tFileInputDelimited to tMSSqlOutput using a Row > Main link.
-
Do the same to connect tMSSqlInput to
tLogRow.
Opening a connection to the MSSQL server
-
Double-click the tMSSqlConnection
component to open its Basic settings view
in theComponent tab. -
In the Host field, type in the IP address
or hostname of the MSSQL server, 192.168.30.47 in this example. -
In the Port field, type in the port
number of the database server, 1433 in
this example. -
In the Schema field, type in the schema
name, dbo in this example. -
In the Database field, type in the
database name, talend in this
example. -
In the Username and Password fields, enter the credentials for the MSSQL
connection.
Reading the input data
-
Double-click the tFileInputDelimited
component to open its Component view. -
Click the […] button next to the
File Name/Stream field to browse to the
input file. In this example, it is D:/Input/Employee_Wage.txt. This text file holds three
columns: id, name and wage.1234567891011id;name;wage51;Harry;230040;Ronald;379617;Theodore;217421;James;19862;George;259189;Calvin;236284;Ulysses;33834;Lyndon;226417;Franklin;178086;Lyndon;3999 -
In the Header field, type in 1 to skip the first row of the input
file. -
Click Edit schema to define the data to
pass on to the tMSSqlOutput component. In
this example, we define id as the key,
and specify the length and precision for each column respectively.Click OK to close the schema editor. A
dialog box opens, and you can choose to propagate the schema to the next
component.Related topic: tFileInputDelimited.
Writing the data into the database table
-
Double-click the tMSSqlOutput component
to open its Basic settings view in the
Component tab. -
Type in required information for the connection or use the existing
connection you have configured before. In this example, we select the
Use an existing connection check box.
If multiple connections are available, select the connection you want to use
from the Component List drop-down
list. -
In the Table field, type in the name of
the table you want to write the data to: Wage_Info in this example. You can also click the […] button next to the Table field to open a dialog box and select a proper
table. -
Select Create table if not exists from
the Action on table drop-down list. -
Select Insert if not exists from the
Action on data drop-down list. -
Click Sync columns to retrieve the schema
from the preceding component.
Extracting useful information from the table
-
Double-click the tMSSqlInput component to
open its Basic settings view in the
Component tab. -
Select the Use an existing connection
check box. If multiple connections are available, select the connection you
want to use from the Component List
drop-down list. -
Click Edit schema to define the data
structure to be read from the table. In this example, we need to read all
three columns from the table. -
In the Table Name field, type in the name
of the table you want to read the data from: Wage_Info in this example. -
In the Query field, fill in the SQL query
to be executed on the table specified. To obtain the data of employees whose
wages are above the average value and order them by id, enter the SQL query
as
follows:123456SELECT *FROM Wage_InfoWHERE wage >(SELECT avg(wage)FROM Wage_Info)ORDER BY id