Question

I am using OCCI to connect Oracle and C++. When i try to access all the records in the table(which has 10 records), the following code snippet displays only 4 records from the table and the program ends with "segmentation fault" message.

Table Employee

Name         Null?    Type
 ------------ -------- ---------------
 ID           NOT NULL NUMBER(6)
 NAME         NOT NULL VARCHAR2(30)
 AGE          NOT NULL NUMBER(3)
 SALARY       NOT NULL NUMBER(6)
 VA                    NUMBER(8,2)

Code

    #include<occi.h>
#include<stdio.h>
#include<iostream>
using namespace oracle::occi;
using namespace std;


int main ()
{
   Environment *env;
   Connection *conn;
   string userName ;
   string password ;
   string database ;

   userName="e224312";
   password="ipgdMCicy";
   database="oraconn";

   cout << "OCCI Demo" << endl;

   env=Environment::createEnvironment(Environment::DEFAULT);
   conn=env->createConnection(userName,password,database);

   cout << "OCCI Environment  and Connection Created " << endl;

   int idx=0;
   int ch;
   int c1;
   string c2;

   int c3;  

   Statement *stmt = conn->createStatement("SELECT * FROM employee");
   cout << "Selecting Records from Table " << endl;
   ResultSet *rs = stmt->executeQuery();

   while(rs->next()){
    c1 = rs->getInt(1);
    c2 = rs->getString(2);
    c3 = rs->getInt(3); 
    cout <<"ID   :" << c1 << endl;
    cout <<"Name :" << c2 << endl;
    cout <<"Age  :" << c3 << endl;
   }
   cout << "Terminating the Connection and The Environment" << endl;
   env->terminateConnection(conn);
   Environment::terminateEnvironment(env);

   cout << "Normal End" << endl;
}

I am using unix g++ compiler. What is the reason for this abrupt end of the execution and how can I correct it?

GDP Stack Trace

 ~/project/test> gdb testgdb
GNU gdb Fedora (6.8-37.el5)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
(gdb) run
Starting program: /home/518377/project/test/testgdb
warning: .dynamic section for "/lib/libm.so.6" is not at the expected address
warning: difference appears to be caused by prelink, adjusting expectations
warning: .dynamic section for "/lib/libc.so.6" is not at the expected address
warning: difference appears to be caused by prelink, adjusting expectations
warning: .dynamic section for "/usr/lib/oracle/10.2.0.4/client/lib/libnnz10.so" is not at the expected address
warning: difference appears to be caused by prelink, adjusting expectations
warning: .dynamic section for "/lib/libdl.so.2" is not at the expected address
warning: difference appears to be caused by prelink, adjusting expectations
warning: .dynamic section for "/lib/libpthread.so.0" is not at the expected address
warning: difference appears to be caused by prelink, adjusting expectations
warning: .dynamic section for "/lib/libnsl.so.1" is not at the expected address
warning: difference appears to be caused by prelink, adjusting expectations
[Thread debugging using libthread_db enabled]
OCCI Demo
[New Thread 0xb7fe08e0 (LWP 32385)]
OCCI Environment  and Connection Created
Selecting Records from Table
Emp Id   :7
Emp Name :Arun
Age      :23
Emp Id   :8
Emp Name :Babu
Age      :25
Emp Id   :9
Emp Name :Catherine
Age      :21
Emp Id   :10
Emp Name :Dinesh
Age      :20

Program received signal SIGSEGV, Segmentation fault.
0x001a09cc in free () from /lib/libc.so.6
Was it helpful?

Solution

It is the Problem with g++ compiler. It worked when i used gcc compiler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top