Sharing a database connection between a parent Job and a child Job


This article demonstrates how to use the Use and register a shared DB Connection feature to share DB connection between a parent Job and a child Job. With this feature, you can benefit from the following advantages:

  • Using the same single DB connection between a parent Job and a child Job, instead of creating multiple DB connections
  • Implementing transaction management between a parent Job and a child Job
  • Improving project development efficiency



This procedure was written with:

  • Talend Open Studio for Data Integration 5.4.1-r111943
  • JDK version: Sun JDK build 1.6.0_26-b03
  • Operating system: Windows XP SP3
  • Mysql 5.0.67-community-nt

Talend verified this procedure to be compatible with Data Integration releases starting from v4.2.3.



Create example Jobs

In this tutorial, you create two Jobs to learn how to use the 'Use or register a shared DB connection' feature. Call them ParentJob and ChildJob. Using a Mysql database as an example, the detailed Job settings are described below.


Note: This example Job is also available in the attached zip file.






For tMysqlConnection_1:

  • Create a Mysql DB connection, select the Use or register a shared DB connection box to register a shared DB connection, and type a connection name in the Shared DB connection Name field, for example "Conn".



For tFixedFlowInput_1:

  • Generate a set of test data.



For tMysqlOutput_1:

  • Insert the data into a table called "person". Select the Use an existing connection box to use an existing connection created on tMysqlConnection_1. Select Drop table if exists and create from the Action on table list. This means the Job will create the table if it doesn't exist, or drop the table if it already exists and create it again.



For tRunJob_1:

  • Call the ChildJob Job.



For tMysqlCommit:

  • If the Job works properly, commit the changes and close the DB connection.


For tMysqlRollback:

  • If the Job fails, rollback the changes and close the DB connection.






For tMysqlConnection_1:

  • Select the Use or register a shared DB connection box to use a shared DB connection and type in the connection name "Conn", which is defined in the ParentJob Job, in the Shared DB connection Name field.


    Note: You don't need to set the DB connection parameters such as Host on this component. Allow them to be empty, as the component will use a shared DB connection.




For tMysqlInput_1:

  • Read data from the "person" table, which is created and filled in by the ParentJob job.


For tLogRow_1:

  • Print the data on the console.


Executing the example Job

Executing the ParentJob Job inserts data into the "person" table from the parent job that are then read from the child job, and are displayed on the console.


Starting job ParentJob at 11:59 11/01/2014.
[statistics] connecting to socket on port 3699
[statistics] connected
|tLogRow_1 |
|id|name   |
|1 |Shong  |
|2 |Elise  |
|3 |Pedro  |
|4 |Patrick|
|5 |Dave   |
[statistics] disconnected
Job ParentJob ended at 11:59 11/01/2014. [exit code=0]


Version history
Revision #:
8 of 8
Last update:
‎09-29-2018 12:12 AM
Updated by:
Labels (2)
Four Stars

Dear Sparks,


i implemented shared eared connection with subjob. But connection in the main job is getting closed before subjob complete. I am getting closed connection error.


could you please suggest me to resolve the problem.




Community Manager

Hi Harinadh,


Sorry for the delay in replying. For assistance if this is still a problem, please log on to If you would like help from the community, please post your question to the correct forum.


Hope that helps,


Six Stars

Great article!
I was excited to find this; because I like the premise of having 1 open connection that is shared; then closed.

However; for me; I needed to wire this up using a tCassandraConnection; instead of a tMySqlConnection; and alas the tCassandraConnection doesn't expose a property
"Use or register a shared DB connection"
to use to accomplish this.

You would think Talend would be consistent in common properties like this across all of its DB Connection components.