// This module is included in the following assemblies:
// as_connecting-to-databases.adoc

[id='adding-db-connection-finish-middle_{context}']
= Accessing a database in the middle or to complete an integration

In an integration, you can access a database in the 
middle of a flow or to finish a simple integration. To do this, add 
a database connection to the middle of a flow or as a simple 
integration's finish connection. 

.Prerequisites
* You created a database connection.
* You are creating or editing a flow and {prodname} is prompting you
to add to the integration. Or, {prodname} is prompting you to choose a finish connection. 

.Procedure
. On the *Add to Integration* page, click the plus sign where you 
want to add the connection. Skip this step if {prodname} is
prompting you to choose the finish connection. 
. Click the database connection for the database that you want to access.
. On the *Choose an action* page, select one of the following:
+
* *Invoke SQL* operates on data by executing the
SQL statement you specify.
+
Note that the Database Connector accepts most basic SQL syntax. If you want to use a complex SQL statement, you should use a stored procedure instead since the Database Connector does not validate the SQL syntax in a stored procedure.        

* *Invoke stored procedure* operates on data by invoking
the stored procedure that you specify or select.
. If you selected *Invoke SQL*, in the *SQL Statement* field:
** For a middle connection, enter a SQL `SELECT` statement that obtains
one or more records or enter a SQL `INSERT`, `UPDATE`, or
`DELETE` statement that
operates on one or more records.
The database table that contains the data must already exist.

** For a finish connection, enter a SQL `INSERT`, `UPDATE` or
`DELETE` statement to
operate on one or more records.

** In the *Batch update* field, accept *No*, which is the default, 
or select *Yes*. 
+
The setting of *Batch update* affects connection behavior when the 
input to this action is a collection, and the SQL statement inserts, 
deletes, or updates records. The default behavior (*Batch update* is *No*) 
is that the connection accepts only individual objects and executes the 
SQL statement once for each object. When *Batch update* is *Yes*, 
the connection accepts a collection as the input to the action. 
The connection executes the SQL statement once and uses all collection 
items as input to a batch update operation.  

+
If you selected *Invoke stored procedure*, in the
*Procedure name* field, select or enter the name of the stored procedure to
invoke to operate on the data of interest. The stored procedure you specify must
already exist. The database administrator should have created any stored
procedures you need to use in an integration.  

. Click *Next*.

.Result
{prodname} tries to validate the connection, which includes
checking that a specified SQL query is syntactically correct and
confirming that the query or stored procedure target data exists. If
verification is successful then {prodname} adds the connection to
the flow. If verification fails then {prodname} displays a message
about the problem. Update your input as needed and try again.

.Additional resource
link:{LinkSyndesisConnectorGuide}about-parameter-placeholders-and-values_db[About parameter placeholders and values in SQL statements that update data].
