首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >occi分段错误

occi分段错误
EN

Stack Overflow用户
提问于 2011-11-01 15:37:03
回答 1查看 1.4K关注 0票数 0

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

表Employee

代码语言:javascript
复制
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)

代码

代码语言:javascript
复制
    #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堆栈跟踪

代码语言:javascript
复制
 ~/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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-14 10:30:26

这是g++编译器的问题所在。当我使用gcc编译器时,它起作用了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7963655

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档