ASA Programming Guide
Using SQL in Applications
Preparing 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)
Prepare the statement.
Set up bound parameters, which will hold values in the statement.
Assign values to the bound parameters in the statement.
Execute the statement.
Repeat steps 3 and 4 as needed.
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)
Prepare the statement using the EXEC SQL PREPARE command.
Assign values to the parameters in the statement.
Execute the statement using the EXE SQL EXECUTE command.
Free the resources associated with the statement using the EXEC SQL DROP command.
To use a prepared statement (ODBC)
Prepare the statement using SQLPrepare.
Bind the statement parameters using SQLBindParameter.
Execute the statement using SQLExecute.
Drop the statement using SQLFreeStmt.
For more information, see Executing prepared statements and the ODBC SDK documentation.
To use a prepared statement (ADO.NET)
Create an AsaCommand object holding the statement.
AsaCommand cmd = new AsaCommand( "select emp_lname from employee", conn );
Declare data types for the parameters in the statement.
Use the AsaCommand.CreateParameter method.
Prepare the statement using the Prepare method.
cmd.Prepare();
Execute the statement.
AsaDataReader reader = cmd.ExecuteReader();
For more information, see
To use a prepared statement (JDBC)
Prepare the statement using the prepareStatement method of the connection object. This returns a prepared statement object.
Set the statement parameters using the appropriate setType methods of the prepared statement object. Here, Type is the data type assigned.
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)
Prepare the statement using the ct_dynamic function, with a CS_PREPARE type parameter.
Set statement parameters using ct_param.
Execute the statement using ct_dynamic with a CS_EXECUTE type parameter.
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.