occi分段错误错误

时间:2011-11-01 07:37:03

标签: c++ oracle oracle10g segmentation-fault occi

我使用OCCI连接Oracle和C ++。当我尝试访问表中的所有记录(有10条记录)时,以下代码片段仅显示表中的4条记录,程序以“分段错误”消息结束。

表员工

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)

代码

    #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;
}

我正在使用unix g ++编译器。这种突然结束执行的原因是什么,我该如何纠正呢?

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

1 个答案:

答案 0 :(得分:0)

这是g ++编译器的问题。当我使用gcc编译器时它工作。