Contents Index Preparing statements Introduction to cursors

ASA Programming Guide
  Using SQL in Applications
    Preparing statements

How to use prepared statements


This section provides a brief overview of how to use prepared statements. The general procedure is the same, but the details vary from interface to interface. Comparing how to use prepared statements in different interfaces illustrates this point.

To use a prepared statement (generic)

  1. Prepare the statement.

  2. Set up bound parameters, which will hold values in the statement.

  3. Assign values to the bound parameters in the statement.

  4. Execute the statement.

  5. Repeat steps 3 and 4 as needed.

  6. Drop the statement when finished. This step is not required in JDBC, as Java's garbage collection mechanisms handle this for you.

To use a prepared statement (embedded SQL)

  1. Prepare the statement using the EXEC SQL PREPARE command.

  2. Assign values to the parameters in the statement.

  3. Execute the statement using the EXE SQL EXECUTE command.

  4. Free the resources associated with the statement using the EXEC SQL DROP command.

To use a prepared statement (ODBC)

  1. Prepare the statement using SQLPrepare.

  2. Bind the statement parameters using SQLBindParameter.

  3. Execute the statement using SQLExecute.

  4. Drop the statement using SQLFreeStmt.

    For more information, see Executing prepared statements and the ODBC SDK documentation.

To use a prepared statement (ADO.NET)

  1. Create an AsaCommand object holding the statement.

    AsaCommand cmd = new AsaCommand(
         "select emp_lname from employee", conn );
  2. Declare data types for the parameters in the statement.

    Use the AsaCommand.CreateParameter method.

  3. Prepare the statement using the Prepare method.

    cmd.Prepare();
  4. Execute the statement.

    AsaDataReader reader = cmd.ExecuteReader();

For more information, see

To use a prepared statement (JDBC)

  1. Prepare the statement using the prepareStatement method of the connection object. This returns a prepared statement object.

  2. Set the statement parameters using the appropriate setType methods of the prepared statement object. Here, Type is the data type assigned.

  3. Execute the statement using the appropriate method of the prepared statement object. For inserts, updates, and deletes this is the executeUpdate method.

    For more information on using prepared statements in JDBC, see Using prepared statements for more efficient access.

To use a prepared statement (Open Client)

  1. Prepare the statement using the ct_dynamic function, with a CS_PREPARE type parameter.

  2. Set statement parameters using ct_param.

  3. Execute the statement using ct_dynamic with a CS_EXECUTE type parameter.

  4. Free the resources associated with the statement using ct_dynamic with a CS_DEALLOC type parameter.

    For more information on using prepared statements in Open Client, see Using SQL in Open Client applications.


Contents Index Preparing statements Introduction to cursors