Configuring datasource in Talend Runtime - 6.2

Talend Data Fabric Studio User Guide

EnrichVersion
6.2
EnrichProdName
Talend Data Fabric
task
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

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 the Talend Installation Guide.

Installing MySQL driver into a container

The Talend ESB package provides JDBC drivers only for the Derby database. 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.

To do so, in a Talend Runtime container, run the following command (change the database version numbers if applicable):

bundle:install mvn:mysql/mysql-connector-java/5.1.18

For more information on how to install the H2, Oracle, DB2, SQLServer and PostgreSQL JDBC drivers into a container, see the section on datasource installation in the Infrastructure Services Configuration Guide.

Setting the datasource configuration file

The MySQL datasource configuration file named datasource-mysql.xml can be found in the <TalendRuntimePath>/add-ons/datasources/dataservice folder.

<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>

Set the database connection details in the configuration file, and copy it to the deploy folder within the Talend Runtime container directory. The datasource alias jdbc/sample will be used in the MySQL database components when configuring the Job in the Studio. You can also change it as needed.