473,624 Members | 2,612 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

oracle-c++

How to connect to oracle using C++ program and select some data from a
table?

Dec 10 '05 #1
6 4933
On 10 Dec 2005 05:48:04 -0800, "sarat" <sh*******@gmai l.com> wrote:
How to connect to oracle using C++ program and select some data from a
table?


You have posted three duplicate messages; one would have been quite
sufficient.

In order to connect to any database, you will need to use either the
API that comes with that product, or a third-party middleware such as
ODBC or OLEDB which have a C++ binding.

Have you tried:
comp.databases. oracle?
Google?
The Oracle website?

--
Bob Hairgrove
No**********@Ho me.com
Dec 10 '05 #2

Bob Hairgrove wrote:
You have posted three duplicate


Hmm, does that mean six?

Triplicate :-)

Gavin Deane

Dec 10 '05 #3
Hi,

You can connect to oracle either using ODBC (typically from a windows PC) or
using OCI (Oracle Call Interface). Look for the OCI manual on the oracle
site.


For instance:
////////////////////////////////////////////////////////////

// OCIConnection.c c

//-----------------------------------------------------------

// Author : Ron AF Greve

// Date : 20011104

// EMail : software THESIGN moonlit xs4all nl

// CopyRight 2001 by Ron AF Greve

//-----------------------------------------------------------

// Function : Connection to the database

//

////////////////////////////////////////////////////////////

static char rcsid[] = "$Id: OCIConnection.c c,v 1.7 2002/03/05 09:26:44
rgreve Exp rgreve $";

#include "OCIConnection. h"

#include <iostream>

bool COCIConnection: :OCIInitialized = false;

COCIConnection: :COCIConnection ( const string& User, const string&
Password ):

User ( User ),

Password ( Password ),

HEnv ( 0 ),

HError ( 0 ),

HServer ( 0 ),

HService ( 0 ),

HAuth ( 0 ),

Attached ( false ),

Session ( false )

{

Init();

}

COCIConnection: :COCIConnection ( const string& Server, const string& User,
const string& Password ):

Server ( Server ),

User ( User ),

Password ( Password ),

HEnv ( 0 ),

HError ( 0 ),

HServer ( 0 ),

HService ( 0 ),

HAuth ( 0 ),

Attached ( false ),

Session ( false )

{

Init();

}

void COCIConnection: :Init()

{

if( !OCIInitialized )

{

OCIInitialize( OCI_DEFAULT, 0, 0, 0, 0 );

OCIInitialized = true;

}

OCIEnvInit( &HEnv, OCI_DEFAULT, 0, 0 );

//OCIEnvCreate( &HEnv, OCI_DEFAULT, 0, 0, 0, 0, 0, 0 );

OCIHandleAlloc( reinterpret_cas t<const dvoid *>( HEnv ),
reinterpret_cas t<dvoid **>( &HService ), OCI_HTYPE_SVCCT X, 0, 0 );

OCIHandleAlloc( reinterpret_cas t<const dvoid *>( HEnv ),
reinterpret_cas t<dvoid **>( &HError ), OCI_HTYPE_ERROR , 0, 0 );

OCIHandleAlloc( reinterpret_cas t<const dvoid *>( HEnv ),
reinterpret_cas t<dvoid **>( &HServer ), OCI_HTYPE_SERVE R, 0, 0 );

}

bool COCIConnection: :Connect()

{

try

{

SetStatus( OCIServerAttach ( HServer, HError, Server.size() ?
reinterpret_cas t<const text *>( Server.c_str() ) : 0, Server.size(),
OCI_DEFAULT ) );

if( GetStatus() != OCI_SUCCESS )

{

cerr << __FILE__ << ":" << __LINE__ << " " << Report( HError ) << endl;

}

else

{

Attached = true;

// set attribute server context in the service context

SetStatus( OCIAttrSet( HService, OCI_HTYPE_SVCCT X, HServer, 0,
OCI_ATTR_SERVER , HError ) );

if( GetStatus() != OCI_SUCCESS )

{

cerr << __FILE__ << ":" << __LINE__ << " " << Report( HError ) << endl;

}

else

{

SetStatus( OCIHandleAlloc( reinterpret_cas t<const dvoid *>( HEnv ),
reinterpret_cas t<dvoid **>( &HAuth ), OCI_HTYPE_SESSI ON, 0, 0 ) );

if( GetStatus() != OCI_SUCCESS )

{

cerr << __FILE__ << ":" << __LINE__ << " " << Report( HError ) << endl;

}

else

{

OCIAttrSet( HAuth, OCI_HTYPE_SESSI ON, const_cast<dvoi d *>(
reinterpret_cas t<const dvoid *>( User.c_str() ) ), User.size(),
OCI_ATTR_USERNA ME, HError );

OCIAttrSet( HAuth, OCI_HTYPE_SESSI ON, const_cast<dvoi d *>(
reinterpret_cas t<const dvoid *>( Password.c_str( ) ) ), Password.size() ,
OCI_ATTR_PASSWO RD, HError );

SetStatus( OCISessionBegin ( HService, HError, HAuth, OCI_CRED_RDBMS,
OCI_DEFAULT ) );

if( GetStatus() != OCI_SUCCESS )

{

cerr << __FILE__ << ":" << __LINE__ << " " << Report( HError ) << endl;

}

else

{

Session = true;

OCIAttrSet( HService, OCI_HTYPE_SVCCT X, HAuth, 0, OCI_ATTR_SESSIO N,
HError );

}

}

}

}

}

catch( ... ){}

return OCI_SUCCESS == GetStatus();

}

COCIStatement *COCIConnection ::CreateStateme nt( const string& Statement )

{

COCIStatement *OCIStatement = 0;

if( OCI_SUCCESS == GetStatus() )

{

OCIStatement = new COCIStatement( HService, HEnv, HError, Statement );

}

return OCIStatement;

}

COCIConnection: :~COCIConnectio n()

{

if( Session )

{

OCISessionEnd ( HService, HError, HAuth, OCI_DEFAULT );

}

if( Attached )

{

OCIServerDetach ( HServer, HError, OCI_DEFAULT );

}

if( HServer )OCIHandleFree( HServer, OCI_HTYPE_SERVE R );

if( HService )OCIHandleFree( HService, OCI_HTYPE_SVCCT X );

if( HAuth )OCIHandleFree( HAuth, OCI_HTYPE_SESSI ON );

if( HError )OCIHandleFree( HError, OCI_HTYPE_ERROR );

if( HEnv ) OCIHandleFree( HEnv, OCI_HTYPE_ENV );

// OCITerminate( OCI_DEFAULT );

}

//#define TEST

#ifdef TEST

#include <unistd.h>

int main( int ArgC, char *ArgV[] )

{

while( true )

{

COCIConnection *Connection = new COCIConnection( "", "RGREVE", "FRUTSN6" );

if( !Connection->Connect() )

{

cerr << "Fail" << endl;

}

else

{

char Name[ 200 ];

char Pct_Free[ 200 ];

int Percent = 30;

cin >> Percent;

memset( Name, 0, sizeof Name );

// COCIStatement *Statement = Connection->CreateStatemen t( "SELECT
TABLESPACE_NAME FROM DBA_FREE_SPACE" );

COCIStatement *Statement = Connection->CreateStatemen t(

"SELECT a.tablespace_na me TSNAME, "

"SUM(a.sumb)*10 0/sum(a.tots) Pct_Free "

"FROM (SELECt tablespace_name , 0 tots, SUM(bytes) sumb, "

"MAX(bytes) largest, COUNT(*) chunks "

"FROM dba_free_space a "

"GROUP BY tablespace_name "

"UNION ALL "

"SELECT tablespace_name , SUM(bytes) tots, 0, 0, 0 "

"FROM dba_data_files "

"GROUP BY tablespace_name ) a "

"group by a.tablespace_na me "

"having SUM(a.sumb)*100/sum(a.tots) < :Percent"

);

Statement->DefineByPos( 1, Name, sizeof Name );

Statement->DefineByPos( 2, Pct_Free, sizeof Pct_Free );

Statement->BindByName( ":Percent", &Percent );

Statement->Execute();

while( Statement->Fetch() )

{

cerr << "Name = " << Name << " Pct_Free " << Pct_Free << endl;

}

delete Statement;

}

delete Connection;

Connection = 0;

sleep(1);

}

return 0;

}

#endif
--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

"sarat" <sh*******@gmai l.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
How to connect to oracle using C++ program and select some data from a
table?

Dec 10 '05 #4
On 10 Dec 2005 06:13:10 -0800, de*********@hot mail.com wrote:

Bob Hairgrove wrote:
You have posted three duplicate
Hmm, does that mean six?


Possibly, but I only saw three. ;)
Triplicate :-)


One could also say: "He posted three messages, all duplicates of the
same message."

--
Bob Hairgrove
No**********@Ho me.com
Dec 10 '05 #5

"sarat" <sh*******@gmai l.com> wrote in message news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
How to connect to oracle using C++ program and select some data from a
table?


Look at C++-Wrapper around Oracle
* http://groups.google.com/groups?th=ff043117b474f920
* http://alexvn.freeservers.com/s1/download.html (Click on "C++-wrapper around Oracle ")
* http://www.codearchive.com/list.php?go=0705
* http://www.planet-source-code.com/vb...=3537&lngWId=3

--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

Dec 10 '05 #6
sarat wrote:
How to connect to oracle using C++ program and select some data from a
table?


In U++ (http://upp.sf.net):

#include <Oracle/Oracle7.h>

CONSOLE_APP_MAI N
{
Oracle7 oracle;
oracle.Open("sc ott/tiger@yorserver ");
Sql sql(oracle);
sql.Execute("se lect ENAME, JOB from EMP");
while(sql.Fetch ())
Cout() << String(sql[0]) << ": " << String(sql[1]);
}

Mirek
Dec 11 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5220
by: Jan Bols | last post by:
I've been trying to install Oracle 8.1.7 on a fresh Mandrake 9.1 O.S for days, but I'm still not able to get it running. I've tried several install instructions that I found on the internet but no luck yet. Here is a short description of what I did so far: 1. I installed the jdk118_v3-glibc-2.1.3.tar in the /usr/local/ dir and made a symbolic link from /usr/local/java to this 2. I installed all the necessary groups and users (oracle,...
4
19984
by: susmita_ganguly | last post by:
Hi I am trying to upgrade from oracle 8i to oracle 9i on the same server ..I don't know much abt migration . Can anyone help me out. Thanks. Susmita
63
25608
by: Nick Palmer | last post by:
Hi all, Is there a DB2 equivilant to Oracle's DB Link functionality ? I have two DB2 databases and I need to get access to the tables in one from the other. In Oracle I would just create a DB Link between the two instances. Is such a thing possible between two DB2 databases ? Thanks in advance, Nick
3
23450
by: Jon Ole Hedne | last post by:
My Access 2002-application need to work with tables from both Oracle and Access. To solve this, I want to run some querys on three views in Oracle and import the results into temporary Access-tables. I have tried this: conn.Provider = "Microsoft.Jet.OLEDB.4.0" conn.ConnectionString = "data source=" & datafil & ";Jet OLEDB:Database Password=" conn.Open datafil
13
7464
by: Chris Botha | last post by:
The machine is running XP Pro with all the latest service packs, etc. I must access an Oracle database so I installed the Oracle client stuff. I can query Oracle from a Windows app, no problem. Using the exact same code (copy and paste) into a Web app I get the following error "Error while trying to retrieve text for error ORA-01019". Security I thought, so I use Impersonation on the Web site, then the aspnet_wp.exe crashes with "The...
2
14227
by: Vinod Sadanandan | last post by:
All, Below listed are the new features in Oracle 11g ,please join me in this discussion to generate a testcase and analyze each of the listed features . Precompilers: Additional Array INSERT and SELECT Syntax Support by Pro*C/C++ and Pro*COBOL Precompilers: Dynamic SQL Statement Caching in Pro*C/C++ and Pro*COBOL Precompilers: Fix Execution Plan in Pro*C/C++ and Pro*COBOL Precompilers: Flexible B Area Length...
2
3556
by: Ruslan A Dautkhanov | last post by:
Hello ! I'm about to install O9i on FreeBSD box. uname -a: FreeBSD stat2.scn.ru 5.2.1-RELEASE-p3 FreeBSD 5.2.1-RELEASE-p3 #2: Fri Apr 23 19:19:43 KRAST 2004 rd@stat2.scn.ru:/usr/src/sys/i386/compile/RDSTAT2-ORACLE i386 uname -a under oracle user : Linux stat2.scn.ru 2.4.2 FreeBSD 5.2.1-RELEASE-p3 #2: Fri Apr 23 19:19:43 KRAST 2004 i686 unknown
0
3311
by: Jack | last post by:
Training Classes for Oracle10g, 9i, 8i Certification training in Oracle10g and 9i: DBA, Developer, Discoverer. training conducted at your location worldwide. Courseware licensing also available. http://a.uuload.com/Oracle-Database.htm Unlock the Value of Your IT System Confio Software's Ignite for Oracle uses wait-event analysis to improve database performance by 65% or more. Gain visibility of every Oracle wait event. Download free...
0
3283
by: Winder | last post by:
Training Classes for Oracle10g, 9i, 8i Certification training in Oracle10g and 9i: DBA, Developer, Discoverer. training conducted at your location worldwide. Courseware licensing also available. http://a.uuload.com/Oracle-Database.htm Unlock the Value of Your IT System Confio Software's Ignite for Oracle uses wait-event analysis to improve database performance by 65% or more. Gain visibility of every Oracle wait event. Download free...
0
4631
by: sathyguy | last post by:
when i type the below in my RHEL AS 4's Firefox 1.5 http://appsworld.ncc.com:7777/forms/...&form=test.fmx iam getting the below error... The requested URL /forms/frmservlet was not found on this server. formsweb.cfg contents...... baseHTML=/u01/app/oracle/OraHome_1/forms/server/base.htm
0
8246
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8179
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8631
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8490
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.