Skip to content

JDBC : How to link Fast2 and SQL DB

Cover image for JDBC cookbook

To extract from or inject in a SQL DataBase, Fast2 use JDBC as a connector with SQL.

Requirements

To use JDBC you must download the library related to your SQL DataBase.

JDBC and SQLServer 2019

To begin, download the JDBC Driver for SQLServer

You must choose the right version for your JDK !

You have two ways to check it :

  1. From a command line:

    echo %JAVA_HOME%
    
  2. Or, check it in your Fast2: FAST2_HOME/config/env.properties

After that you can add:

  • The .jar file in your Fast2: FAST2_HOME/Worker-libs/
  • The .dll in you java folders java/java-version/jre/bin

Use the SQL Server Configuration Manager to start the TCP port.

Example: Injection on a SQL DataBase

For the educational aspect of this topic, let us take this map as an example

Map Fast2 with SQL task

and consider this table to inject in:

CREATE TABLE table_test_connection
(
    column_A int primary key,
    column_B varchar(100)
)

How to configure the SQLStatementTask

Basically, two fields are mandory:

  • The JDBC link to establish the connection between Fast2 and SQLServer. To generate it, use the Microsoft Documentation

    SQL Generic Caller task configuration

    For example, you can use :

    jdbc:sqlserver://localhost;databaseName=demo;encrypt=false;integratedSecurity=true;
    

    If you do not want to put your credentials in the login URL, you can encrypt your password by entering your credentials by filling in the fields below.

    SQL Generic Caller task configuration without password

  • The query to insert or update your database.

    INSERT INTO table_test_connection (column_A, column_B) VALUES ('${punnetId}', "test");
    

    SQLStatement

Now let's start your Fast2 map and check that your table has new values !

SELECT * from table_test_connection;

Before and after, results comparison

👏 Fast2: 1, JDBC & SQL: 0

Congrats, you've made it !

Now you can also use the JDBC connection for other tasks such as SQLMultiQueryTask or SQLSource.
In addition to inserting or updating your database, you can also use these tasks to remove the contents of your tables !