executeSQL()

Executes a static SQL query by specifying its syntax and an optional parameter array.

Syntax

void executeSQL(String query)
 void executeSQL(String query, Vector queryParameters)
 

Parameters

query
A string representation of the SQL query to execute in the database.
queryParameters
A Vector object of arguments to pass to parameters in the SQL query.

Return values

None.

Exceptions

CwDBSQLException - If a database error occurs.

Notes

The executeSQL() method 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 executeSQL() for SQL statements that you need to execute only once. The executePreparedSQL() method saves the executable form (called a prepared statement) and is therefore useful for queries you need to execute multiple times.

Important:
Before executing a query with executeSQL(), you must obtain a connection to the desired database by generating a CwDBConnection object with the getDBConnection() method from the BaseDLM class.

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

Examples

The following example executes a query for inserting rows into an accounting database whose connections reside in the AccntConnPool connection pool.

CwDBConnection connection = getDBConnection("AccntConnPool");
  
 // Begin a transaction
 connection.beginTransaction();
  
 // Insert a row
 connection.executeSQL("insert...");
  
 // Commit the transaction
 connection.commit();
  
 // Release the database connection
 connection.release();
 

For a more complete code sample that selects data from a relationship table, see

See also

executePreparedSQL(), executeStoredProcedure(), getDBConnection(), hasMoreRows(), nextRow()

Copyright IBM Corp. 2003