Welcome to Egypt Forums Mark forums read | Egypt Main Page
Egypt Forums
Arabic Movies



Articles Thread, Connect C++ with Oracle in C and C++; Oracle C++ Call Interface (OCCI) is an Application Programming Interface (API) that provides C++ applications access to data in an ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=24


Reply
LinkBack Thread Tools Display Modes
Connect C++ with Oracle
 
 
Choose
SABRAWY's Avatar

Reply With Quote
 
Join Date: Aug 2007
Posts: 1,893
08-09-2007, 04:40 PM
 
Oracle C++ Call Interface (OCCI) is an Application Programming Interface (API) that provides C++ applications access to data in an Oracle database. This API is a significant improvement to the Oracle Call Interface (OCI) API as far as ease of use is concerned. Engineers who have written JDBC (Java Database Connectivity) code will find the OCCI API to be quite similar to that of JDBC

1) The table that is used in the example code is:

PHP Code:
     CREATE TABLE EMP(
    
empno     NUMBER,
    
ename     VARCHAR2(10),
    
hireDate  Date);
2) Database Query : Select the contents of the EMP table

PHP Code:
     #include <DbManager.h>
#include <iostream>

using namespace std;

using namespace oracle::occi;

const
string sqlString("select empno, ename, hiredate from emp");

const
string dateFormat("DD-MON-YYYY HH24:MI:SS");

int main(int argc, char **argv)

{
    if (
argc != 2)
    {
        
cerr << "\nUsage: " << argv[0] << " <db-user-name>\n" << endl;
        exit(
1);
    }
    
    
// Initialize OracleServices
    
    
DbManager* dbm = NULL;
    
    
OracleServices* oras = NULL;
    
    
Statement *stmt = NULL;
    
    
ResultSet *resultSet = NULL;
    
    
try
    
{
        
        
// Obtain OracleServices object with the default args.
        
        
dbm = new DbManager(userName);
        
        
oras = dbm->getOracleServices();
        
        
// Obtain a cached connection
        
        
Connection * conn = oras->connection();
        
        
// Create a statement
        
        
stmt = conn->createStatement(sqlString);
        
        
int empno;
        
        
string ename;
        
        
Date hireDate;
        
        
string dateAsString;
        
        
// Execute query to get a resultset
        
        
resultSet = stmt->executeQuery();
        
        while (
resultSet->next())
        {
            
            
empno = resultSet->getInt(1);  // get the first column returned by the query;
            
            
ename = resultSet->getString(2);  // get the second column returned by the query
            
            
hireDate = resultSet->getDate(3);  // get the third column returned by the query
            
            
dateAsString="";
            
            
//You cannot check for null until the data has been read
            
            
if (resultSet->isNull(1))
            {
                
cout << "Employee num is null... " << endl;
            }
            if (
resultSet->isNull(2))
            {
                
cout << "Employee name is null..." << endl;
            }
            if (
resultSet->isNull(3))
            {
                
cout << "Hire date is null..." << endl;
            }
            else
            {
                
dateAsString=hireDate.toText(dateFormat);
            }
            
cout << empno << "\t" << ename << "\t" << dateAsString << endl;
            
        }
        
        
// Close ResultSet and Statement
        
        
stmt->closeResultSet(resultSet);
        
        
conn->terminateStatement(stmt);
        
        
// Close Connection and OCCI Environment
        
        
delete dbm;
        
    }
    
catch (SQLException& ex)
    {
        if (
dbm != NULL)
        {
            
dbm->rollbackActions(ex, stmt, resultSet); // free resources and rollback transaction
        
}
    }
    
catch (ExoException& ex1)
    {
        
cerr << "\nCaught ExoException:\n" << ex1.getExceptionText() << endl;
        exit(
2);
    }
    
    return
0;
}
 
 
 
 
Senior Member

Reply With Quote
 
Join Date: Mar 2008
Posts: 205
01-08-2008, 07:12 PM
 
Egypt.Com EnForum
 
 
 
 
The God Father
Developer's Avatar

Reply With Quote
 
Join Date: Jul 2008
Location: NDC
Posts: 5,425
02-08-2008, 12:11 AM
 
awww some topic dude thx
__________________
I Love Walking In The Rain Cuz Nobody Know I'm Crying !!
 
 
 
 
Senior Member

Reply With Quote
 
Join Date: Mar 2008
Posts: 205
06-08-2008, 04:12 AM
 
thanks Sabrawy
nice topic
 
 
 
 
Moderator

Reply With Quote
 
Join Date: Nov 2008
Posts: 101
11-03-2009, 03:43 PM
 
Thank you! Great topic
__________________
PLEASE NO WAREZ - PATCHES OR ANYTHING OF A SIMULAR SORT --- YOU WILL GET BANNED!
 
 
 
Reply

Articles Thread, Connect C++ with Oracle in C and C++; Oracle C++ Call Interface (OCCI) is an Application Programming Interface (API) that provides C++ applications access to data in an ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=24


Bookmarks

Tags
connect, oracle


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Oracle/Java Tutorial Developer Articles 2 11-03-2009 04:07 PM
Oracle PL/SQL Tutorial Developer Articles 0 04-12-2008 02:09 AM
Microsoft Windows Media Connect v2.0 Developer Software and Programs 0 28-10-2008 11:26 PM
Oracle Database 11g PL/SQL Programming (Oracle Press) Developer Articles 0 05-09-2008 09:02 PM
Datatypes in Oracle SABRAWY Articles 6 06-08-2008 12:42 AM