PRO C to connect oracle and C

Go down

PRO C to connect oracle and C

Post by mightyganesh on Wed Apr 28, 2010 7:38 pm

a code using PRO *C to connect oracle and cpp!

include the include u want!

to use c++ use the cin and cout~


Code:
/* program to change the salary of an employee */

#include
#include
#include
#include


EXEC SQL BEGIN DECLARE SECTION;
VARCHAR uid[80];
VARCHAR pwd[20];
int empno;
int sal;

VARCHAR ename[30];
int newsal;

EXEC SQL END DECLARE SECTION;

EXEC SQL INCLUDE SQLCA.H;

void main()
{

  strcpy(uid.arr,"SCOTT");
  uid.len =strlen(uid.arr);
  strcpy(pwd.arr,"TIGER");
  pwd.len = strlen(pwd.arr);

  EXEC SQL WHENEVER SQLERROR GOTO errexit;
  EXEC SQL CONNECT :uid IDENTIFIED BY :pwd;

  /* take employee number from user */
  printf("Enter employee number : ");
  scanf("%d",&empno);

  /* get the details of the employee */
  EXEC SQL WHENEVER NOTFOUND GOTO noemp;
  EXEC SQL select ename, sal into :ename, :sal from emp where empno = :empno;
 
  /* display employee name and salary */
  ename.arr [ ename.len ] = '\0';

  printf("Name : %s  Salary : %d\n", ename.arr, sal);

  printf("Enter new salary : ");
  scanf("%d", &newsal);


  /* update employee record */
  EXEC SQL update emp set sal = :newsal where empno  = :empno;
 
  printf("Updation Successful");

  goto normalexit;
     

noemp:
  printf("Sorry. Invalid employee number. Quitting...");

normalexit:
  EXEC SQL COMMIT WORK RELEASE;
  return;

errexit:
  printf("Error: %70s", sqlca.sqlerrm.sqlerrmc);
}


now to compile this we need to save this file using .pc extension ( sampleproc.pc)

then we to compile using PROC command

PROC sampleproc.pc

then we will get a output with .c extension then i dont know if to compile the .c file directly using g++ compiler or have to link some library headers!!!!!
help out ppl! study scratch Question Crying or Very sad
avatar
mightyganesh

Posts : 53
Points : 92
Join date : 2010-02-26
Age : 30

View user profile http://ganeshguna.blogspot.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum