Click here to Skip to main content
15,889,527 members
Articles / Database Development / SQL Server
Article

C++ wrapper for Oracle's OCI Interface

Rate me:
Please Sign up or sign in to vote.
3.50/5 (2 votes)
27 Sep 2002 129K   3.7K   33   18
This article will provide a cross platform C++ wrapper for Oracle's OCI interface.

Introduction

With this C++ wrapper, you can easily do the following:

  • Connect/disconnect to an Oracle server;
  • Execute SQL select/insert/update/delete commands;
  • Store the query result in a simple linked list;

This project is a cross platform implementation.

class  ObList ;
class  Record ;
class  RecordSet;
int Connect();
int Connect(char *user, char *pass, char *service);
void DisConnect();
int ExecCommand(char* cmdbuf);

Examples:

#include <stdio.h>
#include "dbclient.h"

int main(int argc, char* argv[])
{
    Connect();

    printf("Connect OK.\n");
    RecordSet set;
    set.Open("select * from EMP");
    for(int k=0;k<set.GetRecordsCount();k++)
    {
        Record *pRec=set.GetRecord(k);
        for(int l=0;l<pRec->GetFieldsCount();l++)
        {
            printf("%s",pRec->GetFieldValue(l));
            if(l==(pRec->GetFieldsCount()-1))
                printf("\n");
            else
                printf("\t");
        }
    }
    DisConnect();
    return 0;
}

If you are interested in this article, and want to get details, contact me at lihaijian@sina.com or ema13@dongfang-china.com.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
6 years Programer With VC++

Comments and Discussions

 
Questionlinking error :( Pin
Mustafa Chelik5-Feb-09 5:19
Mustafa Chelik5-Feb-09 5:19 
Generalmy email had changed!w Pin
yt_lhj29-Apr-08 21:41
yt_lhj29-Apr-08 21:41 
QuestionRe: insert? Pin
zuzulica3-Jan-07 11:03
zuzulica3-Jan-07 11:03 
Questioninsert? Pin
cata_100024-Nov-06 10:57
cata_100024-Nov-06 10:57 
GeneralORACLE/ODBC Pin
M_Nuaimi25-Apr-06 13:23
M_Nuaimi25-Apr-06 13:23 
GeneralOracle OCI library Pin
Member 187783613-Apr-05 18:00
Member 187783613-Apr-05 18:00 
GeneralRe: Oracle OCI library Pin
Michael B Pliam22-Feb-07 20:34
Michael B Pliam22-Feb-07 20:34 
After a bit of Googling around, I found that oci.h and oci.lib are distributed with Oracle 10g XE database installation. You must include additional library directories:

C:\oraclexe\app\oracle\product\10.2.0\server\OCI\lib\MSVC (oci.lib)
C:\oraclexe\app\oracle\product\10.2.0\server\OCI\include (oci.h)

You will need to include both these additional library directories to both the dbclient and test applications (they are separate in the project).

You will also need to import the oci.h library using:
#pragma comment (lib, "oci.lib")

This may be a good way to connect to an Oracle database, but I can't get it to work yet, even though it compiles and runs -- the connection is no good. But I may be using it incorrectly.

I tried editing the definitions at the beginning of the dbclient.h file:

#define username "mpliam" //"energyuser"
#define password "silly1" //"ffffff"
#define servicename "MBPORCL1" //"db250"

but get this message:
-- ORACLE error--

ORA-12154: TNS:could not resolve the connect identifier specified

I also tried to use the direct connect function:

Connect(_T("mpliam"), _T("silly1"), _T("MBPORCL1"));

The resulting error was the same.

Any further suggestions greatly appreciated.

Michael Pliam
GeneralCLOB Datatype Pin
Leong Hoe Wai18-Aug-04 19:26
Leong Hoe Wai18-Aug-04 19:26 
Questionhow i can do insert? Pin
andresfecas26-Apr-04 14:03
andresfecas26-Apr-04 14:03 
GeneralUnable to link OCI containing library Pin
Vijaylakshmi18-May-03 19:10
Vijaylakshmi18-May-03 19:10 
GeneralRe: Unable to link OCI containing library Pin
ThoMay2-Mar-05 19:16
ThoMay2-Mar-05 19:16 
Generalmemory bug in source code Pin
scy1-Mar-03 0:33
scy1-Mar-03 0:33 
GeneralRe: memory bug in source code Pin
scy6-Jan-04 14:51
scy6-Jan-04 14:51 
GeneralA simple linklist; Pin
Madmaximus16-Dec-02 4:38
Madmaximus16-Dec-02 4:38 
GeneralRe: A simple linklist; Pin
yt_lhj16-Dec-02 18:14
yt_lhj16-Dec-02 18:14 
QuestionHow can I do ?? Pin
ShanGuohui24-Oct-02 3:11
sussShanGuohui24-Oct-02 3:11 
QuestionHow do you handle two connections ? Pin
Miroslav Rajcic29-Sep-02 21:03
Miroslav Rajcic29-Sep-02 21:03 
AnswerRe: How do you handle two connections ? Pin
lihaijian29-Sep-02 21:30
lihaijian29-Sep-02 21:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.