Thursday, January 21, 2010

OCI, NetBeans and Cygwin


Prerequisites

Here are the software and the versions used
  • OCI Instance Client
    • instantclient-sdk-win32-11.1.0.7.0.zip
    • instantclient-basiclite-win32-11.1.0.7.0.zip
  • NetBeans 6.8
  • Cygwin 1.7.1-1
    • gdb 6.8
    • make 3.81
    • gcc 3.4.4
    • g++ 3.4.4
I am assuming you have unzipped OCI files into d:/oracle

Setup

  1. In NetBeans, create new project. Choose Category: C/C++ and Projects: C/C++ Application.
  2. Give project any name e.g. OCIDemo. Give main file any name e.g. main, but ensure its extension is C rather than C++.
  3. Copy paste code from cdemo81.c to main.c
    1. cdemo81.c is in d:/oracle/instantclient_11_1\sdk\demo
  4. Open OCIDemo project properties using right click on the project name in Project Windows (CTRL + 1).
    1. Go to Category Build -> C Compiler and add D:/oracle/instantclient_11_1/sdk/include to Include Directories
    2. Go to Category Build -> Linker and add D:/oracle/instantclient_11_1/oci.dll to Libraries (not same as Additional Library Directories)

Connection String

cdemo81.c uses scott account for the demo. AS no connection string is given, so edit the line
(void) OCIServerAttach(srvhp, errhp, (text *) "", strlen(""), 0);
to
(void) OCIServerAttach(srvhp, errhp, (text *) "//localhost:1521/orcl", strlen("//localhost:1521/orcl"), (ub4) OCI_DEFAULT);
Note that on my machine SID is ORCL and its available on port 1521. Change this as per your instance setting.

Run

Press F6.

1 comment:

Jaywalker said...

Welcome back to blogosphere