#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sqlda.h>
#include <sqlcpr.h>/* set pro*c operation */
exec sql include sqlca;
exec sql include oraca;
exec oracle option (oraca=yes);/* Define constants for VARCHAR lengths. */
#define     UNAME_LEN      64
#define     PWD_LEN        40/* Declare variables.  No declare section is
  needed if MODE=ORACLE. */
VARCHAR     username[UNAME_LEN];  /* VARCHAR is an Oracle-supplied struct */
varchar     password[PWD_LEN];    /* varchar can be in lower case also. *//* Declare error handling function. */
void sql_error(msg)
   char *msg;
{
   char err_msg[128];
   size_t buf_len, msg_len;   EXEC SQL WHENEVER SQLERROR CONTINUE;   printf("\n%s\n", msg);
   buf_len = sizeof (err_msg);
   sqlglm(err_msg, &buf_len, &msg_len);
   printf("%.*s\n", msg_len, err_msg);   EXEC SQL ROLLBACK RELEASE;
   exit(EXIT_FAILURE);
}void main()
{/* Connect to ORACLE--
* Copy the username into the VARCHAR.
*/
   strncpy((char *) username.arr, "apserver@countserver", UNAME_LEN);/* Set the length component of the VARCHAR. */
   username.len =
     (unsigned short) strlen((char *) username.arr);
/* Copy the password. */
   strncpy((char *) password.arr, "zxc", PWD_LEN);
   password.len =
     (unsigned short) strlen((char *) password.arr);/* Register sql_error() as the error handler. */
   EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--\n");/* Connect to ORACLE.  Program will call sql_error()
* if an error occurs when connecting to the default database.
*/
   EXEC SQL CONNECT :username IDENTIFIED BY :password;   printf("\nConnected to ORACLE as user: %s\n", username.arr);/* Disconnect from ORACLE. */
   EXEC SQL ROLLBACK WORK RELEASE;
   exit(EXIT_SUCCESS);
}