Products | Versions |
---|---|
TIBCO Streaming | 10.6 |
How can I connect to a MySQL database from my Streaming and/or LiveView applications?
jdbc:mysql://<dbhost>:<dbport>/<dbname>..where:
docker pull mysql:5.6.51 docker run --name mysql56 -e MYSQL_ROOT_PASSWORD=P@ssw0rd! -e MYSQL_DATABASE=mysql -e MYSQL_USER=dbuser -e MYSQL_PASSWORD=P@ssw0rd! -p 3306:3306 -d mysql:5.6.51This will start a local MySQL 5.6 database with database name mysql. For this database, you would use the following connection URL:
jdbc:mysql://localhost:3306/mysqlNext, install a compatible MySQL jdbc driver into your Maven repository. To determine the correct driver for your MySQL version, refer to the guidance here. Typically, it is best to download the latest driver that is compatible with both your MySQL database version and the JDK version used to run your Streaming application. For example:
mvn install:install-file -Dfile=mysql-connector-java-8.0.24.jar -DgroupId=mysql -DartifactId=mysql-connector-java -Dversion=8.0.24 -Dpackaging=jarThen add the driver as a dependency in your project's pom.xml:
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.24</version> </dependency>Finally, create a JDBC HOCON configuration:
configuration = { JDBCDataSourceGroup = { jdbcDataSources = { "mysql56" = { driverClassName = "com.mysql.jdbc.Driver" serverURL = "jdbc:mysql://localhost:3306/mysql" userName = "dbuser" password = "P@ssw0rd!" } } } }You are now configured to connect to your MySQL data source.