Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Problem with OCCI, g++ and catching exceptions
Johannes Lochmann <johannes.lochmann_at_chello.at> writes:
> Billy O'Connor schrieb im Artikel <m37kmpgr9s.fsf_at_dpscon.com>:
> >>
> > Johannes,
> > If you can you post the smallest example of code that will compile and
> > produce the error, it would be easier to help track down the problem.
>
> Here is a minimal working code snippet. If you run it once, it works fine
> and inserts 'Hello' into t.t. Second run aborts the program because of
> the violated PRIMARY KEY constraint.
Ok, Johannes, I tried everything I know, I can only get this try/catch block to work if I link statically. BTW, None of Oracle's examples can do exception handling when linked dynamically either...
Here are the compile/link command lines I used:
g++ -c -Wall -pedantic -I$ORACLE_HOME/rdbms/demo -I$ORACLE_HOME/plsql/public -I$ORACLE_HOME/rdbms/public -I$ORACLE_HOME/network/public -o minimal.o minimal.cc
/usr/bin/g++ -L/opt/oracle/product/9.0.1/lib/ -L/opt/oracle/product/9.0.1/rdbms/lib/ -o minimal minimal.o -locci9 -lclntst9 `cat /opt/oracle/product/9.0.1/lib/ldflags` `cat /opt/oracle/product/9.0.1/lib/sysliblist` -ldl -lm
/* CREATE TABLE t(
t VARCHAR(16), CONSTRAINT pk_t PRIMARY KEY(t)); */
#include <occi.h>
#include <iostream.h>
using namespace oracle::occi;
using namespace std;
const string user = "scott";
const string pass = "xxxxxxxx";
int main(int argc, char** argv){
Environment *env = Environment::createEnvironment(); Connection *conn = env->createConnection(user, pass); Statement *stmt = conn->createStatement(); try { string qs = "INSERT INTO t(t) VALUES('Hello')"; stmt->setSQL(qs); stmt->executeUpdate(); conn->commit(); } catch (SQLException excp) { cout << endl << "Exception caught: " << excp.what() << endl; }
![]() |
![]() |