Generic JDBC - Execute

 

In this article

Overview

You can use this Snap to execute a SQL statement/query against a SQL database. This Snap also supports DCL commands (Grant and Revoke).

  • This Snap works only with single queries.

  • This Snap only supports conversion of standard JDBC specification 4.1 types listed here. Learn more about the JDBC 4.1 specification. If you want database-specific conversion, then a database specific Snap pack should be used. For example, for handling TIMESTAMPTZ and TIMESTAMPLTZ formats, you should use the Oracle Snap Pack.

  • The Generic JDBC Execute Snap is used for simple DDL (SELECT, INSERT, UPDATE, DELETE) type statements. This Snap also supports DML operations (CREATE, ALTER, INSERT, and SELECT) when using AWS Athena database.

Snap Type

The Generic JDBC - Execute Snap is a WRITE-type Snap that writes the results of the executed JDBC queries.

Prerequisites

None.

Support for Ultra Pipelines  

Works in Ultra Pipelines

Known Issues

  • If a SELECT query in the SQL statement field in the Snap Settings contains duplicate column names, then the query result displays the column name twice, with the latter prefixed with the table name. If the column name occurs more than twice, the second entry is still prefixed with the table name, but it displays the value of the column mentioned last in the query. The example below illustrates this behavior. 

Example

Consider the following query, where the column name "name" is repeated three times: 

select id, name, city, location, id as name, city as name, location as name from address

Expected output:

The Generic JDBC - Execute Snap's output should reflect the correct query result containing all the six fields, as shown in the image below:

Actual output:

The Snap's output displays the repeat occurrence of the column "name" only once, prefixed with the table name "address" as shown in the image below. Further, it holds the value of the table column "location", which was mentioned last in the SELECT query. 

To avoid this issue, we recommend that you give unique column names in the query.

  • The metadata output in the second output preview is not displayed in table format when your target database is AWS Athena.

  • The suggestions list is not populated for Table name field when your target database is AWS Athena.

  • When the SQL statement property is an expression, the Pipeline parameters are shown in the suggest, but not the input schema.

Snap Views

Type

Format

Number of Views

Examples of Upstream and Downstream Snaps

Description

Type

Format

Number of Views

Examples of Upstream and Downstream Snaps

Description

Input 

Document

  • Min: 0

  • Max: 1

  • Mapper

  • Copy

The input data typically includes the SQL query that you want to execute on your database. The specific format of the input data can vary depending on the design of your pipeline and the data source you are using, but typically it can be the SQL query. In addition to the SQL query, you may also need to provide additional parameters that need to be substituted in the query.

Output

Document

 

  • Min: 0

  • Max: 1

  • JSON Formatter

If an output view is available and an update/insert/merge/delete statement was executed, then the original document that was used to create the statement will be output with the status of the executed statement.

Error

Error handling is a generic way to handle errors without losing data or failing the Snap execution. You can handle the errors that the Snap might encounter when running the Pipeline by choosing one of the following options from the When errors occur list under the Views tab:

  • Stop Pipeline Execution: Stops the current Pipeline execution when the Snap encounters an error.

  • Discard Error Data and Continue: Ignores the error, discards that record, and continues with the remaining records.

  • Route Error Data to Error View: Routes the error data to an error view without stopping the Snap execution.

Learn more about Error handling in Pipelines.

Snap Settings

  • Asterisk ( * ): Indicates a mandatory field.

  • Suggestion icon (): Indicates a list that is dynamically populated based on the configuration.

  • Expression icon ( ): Indicates the value is an expression (if enabled) or a static value (if disabled). Learn more about Using Expressions in SnapLogic.

  • Add icon ( ): Indicates that you can add fields in the field set.

  • Remove icon ( ): Indicates that you can remove fields from the field set.

Field Name

Field Type

Description

Field Name

Field Type

Description

Label*

 

Default ValueGeneric JDBC - Execute
ExampleExecute EmployeeRecords

String

Specify the name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your Pipeline.

SQL statement*

 

Default Value: N/A
Example: INSERT into SnapLogic.book (id, book) VALUES ($id,$book)



String/Expression

 

Specify the SQL statement to execute on the server. 

We recommend you to add a single query in the SQL Statement field.

There are two possible scenarios that you encounter when working with SQL statements in SnapLogic. 

Values can be substituted into the query/statement by using a JSON path using a $ to start the path.
For example, for the given document data:

{ "firstName": "John" }

During design time if you specify query such as,select * from users where first_name = $firstName,

then the run-time query is: select * from users where first_name = "John"

Query type

 

Default Value: Auto
Example: Read

Dropdown list/Expression

Select the type of query for your SQL statement (Read or Write).

When Auto is selected, the Snap tries to determine the query type automatically.
If the execution result of the query is not as expected, you can change the query type to Read or Write.

Pass through

 

Default Value: Selected

Checkbox

Select this checkbox to pass the input data to the output view under the key 'original'. This property applies only to the Execute Snaps with SELECT statement.

 

Ignore empty result

 

Default Value: Deselected

Checkbox

Select this checkbox to ignore empty result; no document is written to the output view when a SELECT operation does not produce any result. If you deselect this checkbox and select the Pass through option, the input document is passed through to the output view.

Number of retries

 

Default Value: 0
Example: 3

Integer/Expression

Specify the maximum number of attempts to be made to receive a response. The request is terminated if the attempts do not result in a response.

Retry interval (seconds)

 

Default Value: 1
Example: 10

Integer/Expression

Specifies the time interval between two successive retry requests. A retry happens only when the previous attempt resulted in an exception. 



Auto commit

 

Default value: Use account setting
Example: True

Dropdown list

Select one of the options for this property to override the state of the Auto commit property on the account. The Auto commit at the Snap-level has three values: TrueFalse, and Use account setting. The expected functionality for these modes are:

  •  True - The Snap will execute with auto-commit enabled regardless of the value set for Auto commit in the Account used by the Snap.

  •  False - The Snap will execute with auto-commit disabled regardless of the value set for Auto commit in the Account used by the Snap.

  • Use account setting - The Snap will execute with Auto commit property value inherited by the Account used by the Snap.

 

Default Value: Execute only
Example: Validate & Execute

Dropdown list

Examples

Executing SQL query to retrieve and insert data

This example pipeline demonstrates how to execute a SQL query to retrieve data from a database and insert the retrieved data into the target database table.

Step 1: Configure the Generic JDBC - Execute Snap with the SELECT query to retrieve all columns from the Account table. On validation, the Snap displays the selected Account records in the output.

 

Step 2: Configure the Generic JDBC - Insert Snap to insert the new data into the NEWTABLE_DOCS table. On validation, the Snap displays the output with the success message of execution.

Downloads

  File Modified

File Example_JDBC_Execute.slp

May 24, 2023 by Amritesh Singh

Snap Pack History