
Component family |
Databases/DB Generic |
|
Function |
tDBInput reads a database and NoteTo use this component, relevant DBMSs’ ODBC drivers should be |
|
Purpose |
tDBInput executes a DB query with NoteFor performance reasons, a specific Input component (e.g.: |
|
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 |
|
![]() |
Click this icon to open the database connection configuration For more information about setting up and storing database |
|
Database |
Name of the data source defined via the database connection |
|
Username and |
DB user authentication data. To enter the password, click the […] button next to the |
|
Schema and Edit |
A schema is a row description. It defines the number of fields to be processed and passed on Since version 5.6, both the Built-In mode and the Repository mode are Note
This component offers the advantage of the dynamic |
|
|
Built-In: You create and store the schema locally for this |
|
|
Repository: You have already created the schema and |
Click Edit schema to make changes to the schema. If the
|
||
|
Table Name |
Name of the source table where changes made to data should be |
|
Query type |
Either Built-in or Since version 5.6, both the Built-In mode and the Repository mode are |
|
|
Built-in: Fill in manually the |
|
|
Repository: Select the relevant |
|
Query |
Enter your DB query paying particularly attention to properly |
Advanced settings |
Additional JDBC parameters |
Specify additional connection properties for the database NoteYou can set the encoding parameters through this field. |
Trim all the String/Char columns |
Select this check box to remove leading and trailing whitespace |
|
|
Trim column |
Remove leading and trailing whitespace from defined |
|
tStatCatcher Statistics |
Select this check box to collect log data at the component |
|
Enable parallel execution |
Select this check box to perform high-speed data processing, by treating multiple data flows
Warning
|
Global Variables |
NB_LINE: the number of rows processed. This is an After
QUERY: the SQL query statement being processed. This is a 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 offers the flexibility of the DB query and covers |
|
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. |
The following scenario creates a two-component Job, reading data from a database using
a DB query and outputting delimited data into the standard output (console).
Warning
As a prerequisite of this Job, the MySQL ODBC driver must
have been installed and the corresponding ODBC connection must have been
configured.
-
Drop a tDBInput and tLogRow component from the Palette to the design workspace.
-
Connect the components using Row > Main link.
-
Double-click tDBInput to open its Basic settings view in the Component tab.
-
Fill in the database name, the username and password in the corresponding
fields. -
Click Edit Schema and create a 2-column
description including shop code and sales. -
Enter the table name in the corresponding field.
-
Type in the query making sure it includes all columns in the same order as
defined in the Schema. In this case, as we’ll select all columns of the schema,
the asterisk symbol makes sense. -
Click on the second component to define it.
-
Enter the fields separator. In this case, a pipe separator.
-
Now go to the Run tab, and click on Run to execute the Job.
The DB is parsed and queried data is extracted from the specified table and
passed on to the job log console. You can view the output file straight on the
console.For an example of the use of Dynamic
Schemas in Input components, see Scenario 4: Writing dynamic columns from a MySQL database to an output file.
StoreSQLQuery is a variable that can be used to debug a tDBInput scenario which does not operate correctly. It allows you to
dynamically feed the SQL query set in your tDBInput
component.
-
Use the same scenario as scenario 1 above and add a third component,
tJava. -
Connect tDBInput to tJava using a trigger connection of the OnComponentOk type. In this case, we want the tDBInput to run before the tJava component.
-
Set both tDBInput and tLogRow component as in tDBInput scenario 1.
-
Click anywhere on the design workspace to display the Contexts property panel.
-
Create a new parameter called explicitly StoreSQLQuery. Enter a default value of 1. This value of 1 means
the StoreSQLQuery is “true” for a use in the
QUERY global variable. -
Click on the tJava component to display the
Component view. Enter the
System.Out.println("")
command to display the query content,
press Ctrl+Space bar to access the variable
list and select the global variable QUERY. -
Go to your Run tab and execute the Job.
-
The query entered in the tDBInput component
shows at the end of the job results, on the log:For an example of the use of dynamic
schemas in Input components, see Scenario 4: Writing dynamic columns from a MySQL database to an output file.