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
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.
The SQL statements you can execute include the following (as long as you have the necessary database permissions):
Use the hasMoreRows() and nextRow() methods to access the retrieved data.
If the connection uses explicit transaction bracketing, you must explicitly start each transaction with beginTransaction() and end it with either commit() or rollback().
To execute stored procedures with OUT parameters, use the executeStoredProcedure() method. For more information, see "Calling stored procedures with executeStoredProcedure()".
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 database table, see "Executing static queries that return data (SELECT)".
See also
executePreparedSQL(), executeStoredProcedure(), getDBConnection(), hasMoreRows(), nextRow()