jdbc_insertΒΆ

jdbc_insert constructs and executes an SQL INSERT statement for each record in the input record stream. Creates table if it does not exist.

jdbc_insert(uri:uri_str, table:table_name_str)
jdbc_insert(uri:uri_str, table:table_name_str, primarykey:field_name_array,
            username:uname_str, password:pswd_str)
where:
  • uri_str - is Jdbc connection string. The format of the string depends on the particular Jdbc driver of the database.
  • table_name_str - name of the table. If the table does not exist it will be created.
  • field_name_array - field names for creating the primary key, expressed as an array of strings. NB! The primary key is created only at table creation. Inserts into the existing table ignore this parameter. Optional.
  • uname_str - username of database user. Optional.
  • pswd_str - password of database user. Optional.

Note

Respective Jdbc drivers must be enabled in configuration.

On successful execution jdbc_insert outputs following:

  • uri - Jdbc connection uri to the database
  • table - affected table
  • rows - number of rows affected by operation
  • field_count - input field count

Example. Store 10 generated records in an sqlite database table test using jdbc_insert command:

1
2
3
4
5
6
dual(10)
| select(time:t, ip, description:s)
| jdbc_insert(uri:'jdbc:sqlite:file:/tmp/test.db'   //test.db must exists in /tmp
              ,table:'test'                         //insert creates table 'test' if it does not exist
              ,primarykey:['time']                  //primary key using field 'time'
);

Note

In order for this example to work: * SQLite JDBC driver must be enabled in SpectX configuration and * an SQLite database must exist in the path specified by JDBC connection string