Icon

2. Write to a Database

<p><strong>Write to a Database</strong></p><p>This workflow shows how to write a data table into a database. In particular, we use the SQLite database here because it is file-based and does not require additional installation.</p><p>This workflow also shows how to performs different kinds of string manipulations and type conversions. To do so, we use the <em>Expression </em>node which allows performing various string, logic, and math operations</p><p><strong><em>Note.</em></strong> This workflow has to be executed <strong>BEFORE </strong>executing the workflow "3. My first Data Exploration".</p>

URL: KNIME Beginner's Luck (Book Homepage) https://www.knime.com/knimepress/beginners-luck

Workflow: Write to a Database


This workflow shows how to write a data table into a database. In particular, we use the SQLite database here because it is file-based and does not require additional installation.

This workflow also shows how to performs different kinds of string manipulations and type conversions. To do so, we use the Expression node which allows performing various string, logic, and math operations

Note. This workflow has to be executed BEFORE executing the workflow "3. My first Data Exploration".

Type Conversion

String replacement

Joining strings

Write data to SQLite Database

Use the SQLite Connector node to connect to the SQLite database. Note that SQLite is a file-based database. The SQLite Connector node thus requires the path of the database file. It also supports the knime:// protocol. The SQLite driver is already included in the SQLite Connector node. Drivers of most popular databases are included in database connector nodes for databases' most recent versions.

Then, connect a DB Writer node to the SQLite Connector node to actually write the data into a new table.

String splitting

iris.csvpath relative to "current workflow"
CSV Reader
Split "class" in iris & <attr> by position<attr> = Setosa/Virginica/Versicolor
Cell Splitter By Position
Split "class" in iris & <attr> by regex<attr> = Setosa/Virginica/Versicolor
String Splitter (Regex)
Replace all "Iris"with "IRIS"
Expression
Replace all Ir* with IRIS
String Replacer
Convert "class_Arr[0]"to UPPERCASE
Expression
Transform Stringback to numbers
String to Number
Add new column "class nr"
Expression
Combine <attr> and "IRIS"into <attr>:IRIS
Column Combiner
Split "petal width" intointeger & floatingby using "." as the delimiter
Cell Splitter
Rearrange column orderfor next node
Column Resorter
Transform Doubleto Integer
Double to Integer
Build <attr>: "IRIS"
Expression
Split "class" in iris & <attr> by delimiter "-"<attr> = Setosa/Virginica/Versicolor
Cell Splitter
write output data table into SQLite database
DB Writer
"petal width" fromDouble to String
Number to String
KBLBook2.sqliteconnect to SQLite databaseknime:// protocol supported
SQLite Connector

Nodes

Extensions

Links