Skip to main content Skip to complementary content

Configuring datasource in Talend Runtime

To use datasource in Talend Runtime, you need to install the MySQL driver in to a container and set the datasource configuration file.

To do so, start a Talend Runtime container first. For more information about how to install Talend ESB Runtime and how to start Talend Runtime container, see Installing Talend Runtime and Running Talend ESB Container.

Installing MySQL driver into a container

To use the MySQL database, its corresponding JDBC driver need to be explicitly installed into the container before installing the datasource. You can install the MySQL driver from a public Maven repository.

Procedure

In a Talend Runtime container, run the following command (change the database version numbers if applicable):

MySQL 5.x

bundle:install mvn:mysql/mysql-connector-java/5.1.18
MySQL 8.x
bundle:install mvn:mysql/mysql-connector-java/8.0.27
For more information on how to install the H2, Oracle, DB2, SQL Server, and PostgreSQL JDBC drivers into a container, see DataSource Installation.

Setting the datasource configuration file

Procedure

  1. Set the database connection details in the MySQL datasource configuration file named datasource-mysql.xml in the <TalendRuntimePath>/add-ons/datasources/dataservice folder.

    For MySQL 5.x:

    <bean id="mysqlDataSource" class="com.mysql.jdbc.jdbc2.optional.
    MysqlConnectionPoolDataSource">
        <property name="url" value="jdbc:mysql://localhost:3306/root"/>
        <property name="user" value="root"/>
        <property name="password" value=""/>
    </bean>
    
    <bean id="dataSource" class="org.apache.commons.dbcp.datasources.
    SharedPoolDataSource" destroy-method="close">
        <property name="connectionPoolDataSource" ref="mysqlDataSource"/>
        <property name="maxActive" value="20"/>
        <property name="maxIdle" value="5"/>
        <property name="maxWait" value="-1"/>
    </bean>
    
    <service ref="dataSource" interface="javax.sql.DataSource">
        <service-properties>
             <entry key="osgi.jndi.service.name" value="jdbc/sample"/>
        </service-properties>
    </service>

    For MySQL 8.x:

    <bean id="mysqlDataSource" class="com.mysql.cj.jdbc.MysqlConnectionPoolDataSource">
        <property name="url" value="jdbc:mysql://localhost:3306/root"/>
        <property name="user" value="root"/>
        <property name="password" value=""/>
    </bean>
    
    <bean id="dataSource" class="org.apache.commons.dbcp.datasources.
    SharedPoolDataSource" destroy-method="close">
        <property name="connectionPoolDataSource" ref="mysqlDataSource"/>
        <property name="maxActive" value="20"/>
        <property name="maxIdle" value="5"/>
        <property name="maxWait" value="-1"/>
    </bean>
    
    <service ref="dataSource" interface="javax.sql.DataSource">
        <service-properties>
             <entry key="osgi.jndi.service.name" value="jdbc/sample"/>
        </service-properties>
    </service>
  2. Copy the configuration file to the deploy folder in the Talend Runtime container directory. The datasource alias jdbc/sample will be used in the MySQL database components when configuring the Job in Talend Studio. You can also change it as needed.

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!