Skip to main content
This guide shows how to load data from a database using a JDBC driver into a store, thanks to the JDBC source. For a description of what the JDBC Source is and other advanced options not included in this guide, refer to the JDBC source.

Basic load example

Goal

The goal is to load the first two columns of the Trades table into the Trades store. Table content Expected Trades content We want to load the first two columns into Trades store.

Setup

First, we need to import the artifact com.activeviam.source:jdbc-source in our project.

Build a source

In order to load data from a database into a datastore, the first step is to build a JDBC source.
A JDBC source is a collection of JDBC topics. JDBC topics are references to a query on the database. A topic is defined using the query language supported by the JDBC driver (most of the time SQL).
Keep in mind that the topic can be configured with more advanced options.

Load into datastore

The second step is to create a channel and use the source to fetch the data into the Datastore.
A channel is the link between a topic and a store.
The way to do so is to provide a channel factory to the source.
Finally, the source can be used to process the channel. The source loads topic content using the channel and stream it into the Datastore.
There is two ways of doing so.
Using the fetch utility:
Or in a manual way:

Access the loaded data

After this loading, you can access your data thanks to the query API.

Load with a parameterized query

Using a prepared statement, you can load data from a JDBC source with a parameterized query. It is identical to the previous example, except for the topic definition:
The rest of the process is the same as in the previous example, except that the parameter value must be provided when fetching the data:

Load with a calculated column

It is also possible to load data from a JDBC source with a calculated column, for example to apply an offset to a column. To do so, one must define a column calculator that will be applied to the column when loading the data:
Then, one must register the column calculator in the channel factory:
And that’s it!