0

Oracle と C++ を接続するためにOCCIを使用しています。テーブル (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 スタック トレース

 ~/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
4

1 に答える 1

0

これはg++コンパイラの問題です。gccコンパイラを使用したときに機能しました。

于 2011-11-14T02:30:26.003 に答える