Execute SQL

Executes a static SQL query by specifying its syntax.

Inputs

Database connection
A CwDBConnection object that represents the database connection.

Query
A String that represents the SQL query to execute in the database.

Exceptions

The Execute SQL function block can throw the CwDBSQLException exception if a database error occurs.

Notes

The Execute SQL function block sends the specified query string as a static SQL statement to the database associated with the current connection. This query is sent as a string to the database, which compiles the string into an executable form and executes the SQL statement, without saving this executable form. Use Execute SQL for SQL statements that you need to execute only once.

Note:
The Execute Prepared SQL and Execute Prepared SQL with Parameter function blocks save the executable form (called a prepared statement) and are therefore useful for queries you need to execute multiple times.
Important

Before executing a query with Execute SQL, you must obtain a connection to the desired database by generating a CwDBConnection object with the Get Database Connection function block.

The SQL statements you can execute include the following (as long as you have the necessary database permissions):

Related information

This function block is based on the CwDBConnection.executeSQL() method. For more information, see executeSQL().

Copyright IBM Corp. 1997, 2004