Skip to end of banner
Go to start of banner

Generic JDBC - Execute

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 71 Next »

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

 Incorrect results for SELECT queries with duplicate column names

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

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 ((blue star)): Indicates a list that is dynamically populated based on the configuration.

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

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

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

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. 

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

Scenarios to successfully execute your SQL statements

Scenario 1: Executing SQL statements without expressions.
If the expression toggle of the SQL statement field is not selected:  

  • The SQL statement must not be within quotes. 

  • The $<variable_name> parts of the SQL statement are expressions. In the below example, $id and $book

  • email = 'you@example.com' or email = $email 

  • emp=$emp

Additionally, the JSON path is allowed only in the WHERE clause. If the SQL statement starts with SELECT (case-insensitive), the Snap regards it as a select-type query and executes once per input document. If not, it regards it as write-type query and executes in batch mode.

Scenario 2: Executing SQL queries with expressions. 
If the expression toggle of the SQL statement field is selected:  

  • The SQL statement must be within quotes. 

  • The + $<variable_name> + parts of the SQL statement are expressions, and must not be within quotes. In the below example, $tablename.

  • The $<variable_name> parts of the SQL statement are bind parameter, and must be within quotes. In the below example, $id and $book.

  • "EMPNO=$EMPNO and ENAME=$EMPNAME"

  • "emp='" + $emp + "'"

  • "EMPNO=" + $EMPNO + " and ENAME='" + $EMPNAME+ "'"

Table name and column names must not be provided as bind parameters. Only values can be provided as bind parameters.

We recommend you use the Oracle - Stored Procedure Snap for invoking procedures when using Oracle database with this Snap due to the following limitation while invoking procedures:

  • Procedures have to invoked as a PL/SQL block (with older JDBC JARs).  However, with this approach the output parameters cannot be sent to the output view. Besides, the latest oracle JDBC drivers do not support PL/SQL.

  • The non-expression form uses bind parameters, so it is much faster than executing N arbitrary SQL expressions.

  • Using expressions that join strings together to create SQL queries or conditions has a potential SQL injection risk and hence unsafe. Ensure that you understand all implications and risks involved before using concatenation of strings with '=' Expression enabled.

  • The '$' sign and identifier characters, such as double quotes (“), single quotes ('), or back quotes (`), are reserved characters and should not be used in comments or for purposes other than their originally intended purpose.

Single quotes in values must be escaped.

Any relational database (RDBMS) treats single quotes (') as special symbols. So, single quotes in the data or values passed through a DML query may cause the Snap to fail when the query is executed. Ensure that you pass two consecutive single quotes in place of one within these values to escape the single quote through these queries.

For example:

If String To pass this valueUse
Has no single quotes
Schaum Series
'Schaum Series'
Contains single quotes
O'Reilly's Publication
'O''Reilly''s Publication'

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"

To invoke procedures when using Oracle database with this Snap, we recommend you use the Oracle Stored Procedure Snap.

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.

If you provide a string value, the Snap displays the following error:
Invalid type (STRING) for property, expecting a value of type integer

You can use a string value only when the field is expression-enabled.

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.

  • Auto commit may be enabled for certain use cases if the PostgreSQL JDBC driver is used in either Redshift, PostgreSQL, or the generic JDBC Snap. However, the JDBC driver may cause out of memory issues when SELECT statements are executed. In those cases, Auto commit in the Snap property should be set to False and the Fetch size in the Account settings can be increased for optimal performance.

  • For a DB Execute Snap, assume that a stream of documents are passed to the input view of the Snap and the SQL statement property has JSON paths in the WHERE clause. If the number of documents are large, the Snap executes in more than one batch rather than executing one per each document. Each batch would contain a certain number of WHERE clause values. If Auto commit is turned on, a failure would only roll back the records in the current batch. If Auto commit is turned off, the entire operation would be rolled back. For a single execute statement (with no input view), the setting has no practical effect.

Behavior of DML Queries in Database Execute Snap when auto-commit is false

DDL queries used in the Database Execute Snap will be committed by the Database itself, regardless of the Auto-commit setting.
When Auto commit is set to false for the DML queries, the commit is called at the end of the Snap's execution.
The Auto commit needs to be true in a scenario where the downstream Snap does depend on the data processed on an Upstream Database Execute Snap containing a DML query.
When the Auto commit is set to the Use account setting on the Snap, the account level commit needs to be enabled.

Snap execution

Default Value: Execute only
Example: Validate & Execute

Dropdown list

Select one of the three modes in which the Snap executes. Available options are:

  • Validate & Execute: Performs limited execution of the Snap, and generates a data preview during Pipeline validation. Subsequently, performs full execution of the Snap (unlimited records) during Pipeline runtime.
  • Execute only: Performs full execution of the Snap during Pipeline execution without generating preview data.
  • Disabled: Disables the Snap and all Snaps that are downstream from it.

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

  1. Download and import the Pipeline into SnapLogic.

  2. Configure Snap accounts as applicable.

  3. Provide Pipeline parameters as applicable.

  File Modified
You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.
No files shared here yet.
  • Drag and drop to upload or browse for files
  • Snap Pack History

     Click here to expand...

    Release 

    Snap Pack Version

    Date

    Type

      Updates

    May 2024

    main26341

    Stable

    Updated and certified against the current SnapLogic Platform release.

    February 2024

    436patches25244

    Latest

    • Fixed an issue with the Generic JDBC-Select, Insert, Update, and Table List Snaps that incorrectly displayed the Schema Name suggestions with the Cassandra driver connection.

    • Fixed an issue with the Generic JDBC-Select Snap that displayed an empty result with the MariaDB driver connection for output 1.

    February 2024

    main25112

    Stable

    Added the following new Snaps to the JDBC Snap Pack:

    November 2023

    435patches24781

    Latest

    The database connection error message in the Generic Database Account is improved for clarity and readability.

    November 2023

    main23721

    Stable

    Updated and certified against the current SnapLogic Platform release.

    August 2023

    main22460

    Stable

    Updated and certified against the current SnapLogic Platform release.

    May 2023

    main21015

     

    Stable

    The Generic Database Account now supports the SSH Tunneling connection. You can now encrypt the network connection between your client and the database server, ensuring a highly secure connection.

    February 2023

    main19844

     

    Stable

    Upgraded with the latest SnapLogic Platform release.

    November 2022

    main18944

     

    Stable

    The Generic JDBC - Insert Snap previously took a longer time to execute and was aborted after a few minutes, which affected the performance of the Snap. The Snap's performance is optimized now and takes lesser time for execution.

    September 2022

    430patches17894

     

    Latest

    The Generic JDBC Snaps connecting to the DB2 database now take lesser time to execute thereby improving the performance.

    August 2022

    main17386

     

    Stable

    Enhanced the Generic Database account Support dynamic values for Account, Advanced, and URL properties.

    4.29 Patch

    429patches16588

     

    Latest

    • Fixed an issue with JDBC Select and JDBC Insert Snaps where the Snaps did not load suggestions for the Table property. Now the Snaps load the suggestions correctly.

    • Enhanced the Generic Database account to support dynamic values for Account properties, Advanced properties, and URL properties so that you can pass these values through Pipeline parameters.

    4.29

    main15993

     

    Stable

    Enhanced the Generic Database Account in the JDBC Snap pack to include Netsuite as an option for the Database name field to connect to the NetSuite database. While configuring the account, if you select Netsuite or Autodetect (if the Snap detects the target database as NetSuite) then the Limit rows field in the Generic JDBC - Select Snap is ignored.

    4.28

    main14627

     

    Stable

    Enhanced the following Snaps to support DML (Data Manipulation Language) operations (CREATE, ALTER, INSERT, and SELECT) when using AWS Athena database.

    4.27

    main12833

     

    Stable

    4.26 

    main11181

     

    Stable

    Upgraded with the latest SnapLogic Platform release.

    4.25 Patch

    425patches11008

     

    Latest

    • Fixed an issue with Generic JDBC - Select Snap where if there are URL properties in the account, the unPooledConnection does not use the properties when creating a connection. This causes the auto-detect functionality to use the wrong database name.

    • Fixed an issue with MySQL and MariaDB in Generic JDBC - Update Snap when a table is incorrectly reported as not being found.

    4.25

    main9554

     

    Stable

    Upgraded with the latest SnapLogic Platform release.

    4.24 Patch

    4.24patches8903

     

    Latest

    Fixes the Pipeline execution failure issue when using the JDBC Snaps with a Microsoft Access account by setting the correct quotation handler for the configured account.

    4.24

    main8556

    Stable

    Enhances the Generic JDBC - Select Snap to return only the fields (provided in the Output Fields) in the output schema (second output view), through a new check box Fetch Output Fields In Schema. If the Output Fields property is empty all the columns are visible.

    4.23 Patch

    423patches8027

     

    Latest

    Fixes the multiple connection issue in the JDBC Snap Pack that occurs when the Auto Detect field is enabled for each execution of the Snap by storing a copy of the database name.

    4.23 Patch

    423patches7800

     

    Latest

    Fixes an issue with JDBC account through a Test Query option that establishes a database connection upon using Auto detect option for the Database name.

    4.23

    main7430

     

    Stable

    • Fixes an issue with the JDBC account that displays a connection is closed error when connecting with the SQL server.

    • Fixes an issue with the JDBC Snaps that fail while displaying the javax.management.MalformedObjectNameException: Invalid character '=' in value part of property error repeatedly when there is “=“ or ”:” in the JDBC URL connection.

    4.22 Patch 

    422patches7246

     

    Latest

    Fixes the file descriptor error in the Snap Pack by removing logging exception which was causing log file spam.

    4.22 Patch

    422patches6772

     

    Latest

    Fixes the issue with Auto detect in Generic JDBC - Execute Snap by implementing the JDBC Auto detect feature to use the correct database name.

    4.22

    main6403

     

    Stable

    Upgraded with the latest SnapLogic Platform release.

    4.21 Patch

    421patches6272

     

    Latest

    Fixes the issue where Snowflake SCD2 Snap generates two output documents despite no changes to Cause-historization fields with DATE, TIME and TIMESTAMP Snowflake data types, and with Ignore unchanged rows field selected.

    4.21 Patch

    421patches6144

     

    Latest

    Fixes the following issues with DB Snaps:

    • The connection thread waits indefinitely causing the subsequent connection requests to become unresponsive.

    • Connection leaks occur during Pipeline execution.

    4.21 Patch

    MULTIPLE8841

     

    Latest

    Fixes the connection issue in Database Snaps by detecting and closing open connections after the Snap execution ends.

    4.21

    snapsmrc542

     

    Stable

    Upgraded with the latest SnapLogic Platform release.

    4.20 Patch

    jdbc8783

     

    Latest

    Fixes the Generic JDBC Execute Snap that adds the value of the previous column's field to a NULL field when SELECT queries having duplicate column names are run on the PostgreSQL database.

    4.20

    snapsmrc535

     

    Stable

    Upgraded with the latest SnapLogic Platform release.

    4.19 Patch 

    db/jdbc8405

     

    Latest

    Fixes an issue with the Generic JDBC - Update Snap wherein the Snap is unable to perform operations when:

    • An expression is used in the Update condition property.

    • Input data contain the character '?'.

    4.19

    snaprsmrc528

     

    Stable

    Upgraded with the latest SnapLogic Platform release.

    4.18

    snapsmrc523

     

    Stable

    Added support for JDBC account Active Directory authentication for SQL server for driver JAR version mssql-jdbc-6.2.2-jre8.jar.

    4.17

    ALL7402

     

    Latest

    Pushed automatic rebuild of the latest version of each Snap Pack to SnapLogic UAT and Elastic servers.

    4.17

    snapsmrc515

     

    Latest

    • Fixes an issue with the Generic JDBC Execute Snap wherein the Snap would send the input document to the output view even if the Pass through field is not selected in the Snap configuration. With this fix, the Snap sends the input document to the output view, under the key original, only if you select the Pass through field.

    • Added the Snap Execution field to all Standard-mode Snaps. In some Snaps, this field replaces the existing Execute during preview check box.

    4.16 Patch

    MULTIPLE7123

     

    Latest

    Added two new properties, Number of retries and Retry interval, to Execute, Insert, Select, and Update Snaps that enables you to handle retry attempts during a connection failure.

    4.16

    snapsmrc508

     

    Stable

    Upgraded with the latest SnapLogic Platform release.

    4.15

    snapsmrc500

     

    Stable

    Upgraded with the latest SnapLogic Platform release.

    4.14

    snapsmrc490

     

    Stable

    Upgraded with the latest SnapLogic Platform release.

    4.13 Patch

    jdbc5231

     

    Latest

    Added binding information for DB2 database connection on the Generic JDBC Snap Pack to ensure that pipelines correctly validate and execute.   

    4.13 Patch

    jdbc5229

     

    Latest

    Added test connection query for SQLMX database in the JDBC Accounts to check if the database connection is valid.

    4.13

    snapsmrc486

     

    Stable

    Upgraded with the latest SnapLogic Platform release.

    4.12 Patch

    MULTIPLE4744

     

    Latest

    Added support to execute multiple queries in a single batch for Snowflake, this patch affects Generic JDBC Execute. 

    4.12

    snapsmrc480

     

    Stable

    Upgraded with the latest SnapLogic Platform release.

    4.11

    snapsmrc465

     

    Stable

    Upgraded with the latest SnapLogic Platform release.

    4.10

    snapsmrc414

     

    Stable

    Adds Auto commit property to the Select and Execute Snaps at the Snap level to support overriding of the Auto commit property at the Account level.

    4.9.0 Patch

    jdbc3242

     

    Latest

    Addresses an issue in JDBC Execute Snap with functions not working (fixes by executing commit() at the end of the processing query).

    4.9.0 Patch

    jdbc3205

     

    Latest

    Fixes auto-commit issue for PostgreSQL SELECT query.

    4.9.0 Patch 

    jdbc3133

     

    Latest

    Fixed error handling of the limit clause by adding Apache Derby support.

    4.9.0 Patch

    jdbc3069

     

    Latest

    Fixed an issue regarding connection not closed after login failure; Expose autocommit for "Select into" statement in PostgreSQL Execute Snap and Redshift Execute Snap.

    4.9

    snapsmrc405

     

    Stable

    Upgraded with the latest SnapLogic Platform release.

    4.8.0 Patch

    jdbc2801

     

    Latest

    Addressed an issue with Generic JDBC - Execute Snap holding the resultset in memory, exhausting memory and causing a core dump.

    4.8.0 Patch

    jdbc2753

     

    Latest

    Potential fix for JDBC deadlock issue.

    4.8

    snapsmrc398

     

    Stable

    • Updated the default value for the property Min pool size to 0. 

    • Info tab added to accounts.

    • Database accounts now invalidate connection pools if account properties are modified and login attempts fail.

    4.7 Patch

    jdbc2195

     

    Latest

    Fixed an issue for database Select Snaps regarding Limit rows not supporting an empty string from a pipeline parameter.

    4.7

    snapsmrc382

     

    Stable

    Upgraded with the latest SnapLogic Platform release.

    4.6

    snapsmrc362

     

    Stable

    • Enhanced Generic JDBC Execute Snap to fully support SQL statements with/without expressions & SQL bind variables.

    • Resolved an issue in Generic JDBC Insert Snap that caused unexpectedly failures on Snowflake and connecting to DB2.

    • Resolved an issue in Generic JDBC Select Snap that caused errors with Teradata database instance.

    • Resolved an issue in Generic JDBC Select Snap with Snowflake account that caused an error when auto-commit was not selected.

    • Resolved an issue in Generic JDBC Select Snap with Snowflake account that caused an error when a merge statement was used in the Snap.

    Known Issue:

    • JDBC Insert: "The Maximum Possible Row Length in the Table is too Large" error message: You will see this message if trying to insert data into Teradata that is larger than Teradata can handle (rows are limited to approximately 64,000 bytes). Workaround: Use smaller default column size, e.g., 32000 bytes.

    4.5.1

    snapsmrc344

     

    Stable

    Resolved an issue with JDBC Select failing with a syntax error when special characters were used.

    4.5

    snapsmrc344

     

    Stable

    • Verified Generic JDBC Snaps connections to Hive. See JDBC Account for configuration information. SELECT and INSERT are supported. SnapLogic does not support UPDATE, DELETE, or MERGE due to limitations in the drivers. 

    • Resolved an issue in Generic JDBC Insert Snap that occurred when inserting records in batches. 

    • Resolved an issue in Generic JDBC Insert Snap that occurred because of an SQL execution (internal) error.

    • Resolved an issue in Generic JDBC Select Snap that occurred because of an SQL query execution. 

    4.4.1

    N/A

     

    Stable

    • Added expression support to the Where clause property for Select Snaps.

    • Resolved an issue with the JDBC Select Snap failing with Teradata because of a Limit Offset.

    • Resolved an issue with JDBC Execute failing to execute a create or replace table statement with Snowflake.

    • Resolved issues with JDBC Insert Snap:

      • Failing to create a table when Create table if not present is selected.

      • An exception occurred when attempting to insert record containing date columns into Teradata.

    4.4

    N/A

     

    Stable

    Upgraded with the latest SnapLogic Platform release.

    4.3.2

    N/A

     

    Stable

    Resolved an issue with Generic JDBC Update updating null into database when an invalid string value is provided as input for time datatype.

    4.3.1

    N/A

    N/A

    Stable

    • New! Generic JDBC SELECT Snap

    • New! Generic JDBC UPDATE Snap

    • Feature: JDBC Snaps - add a new property 'Database name' to JDBC Account

    • Defect: JDBC Execute Snap fails in preview for Oracle timestamp data type

    • Defect: JDBC Insert to Snowflake throws an error

    • Defect: Generic JDBC Execute with JDBC4OLAP drivers to connect to Essbase resulted in com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to parse content type: null

    4.2.2

    N/A

    N/A

    Stable

    • Ignore empty result added to Execute Snap. The option will not write any document to the output view for select statements producing no results.

    • Addressed an issue with idle timeouts.

    • Resolved an issue in JDBC Execute throwing an exception, unable to get driver.

    4.2.1

    N/A

    N/A

    Stable

    • Resolved Generic JDBC Execute not working with value substitution.

    • Resolved JDBC Execute unable to read CLOB columns via jTDS/JDBC.


    Related Content

    • No labels