2

我正在尝试在 Ubuntu 上运行以下测试程序,以使用即时客户端 OCCI 库连接到 Oracle 数据库。

#include <iostream>
#include <occi.h>

using namespace oracle::occi;
int main() {

    Environment *env = Environment::createEnvironment(Environment::DEFAULT);
    Connection *conn = env->createConnection( "user", "1234" ); 
    env->terminateConnection(conn);
    Environment::terminateEnvironment(env);

}

编译时没有错误

g++ main.cpp -L ~/instantclient_12_2 -locci -lclntsh -I ~/instantclient_12_2/sdk/include

但是当我跑步时我得到

terminate called after throwing an instance of 'oracle::occi::SQLException'
  what():  ORA-24960: the attribute  OCI_ATTR_USERNAME is greater than the maximum allowable length of 255
Aborted

我正在运行 Ubuntu 16.04、gcc 5.4.0,并且使用即时客户端 11.2 和 12.2 得到相同的结果。

之前有人问过这个问题:https ://stackoverflow.com/questions/40022118/ora-24960-the-attribute-oci-attr-username-is-greater-than-the-maximum但答案不适用于linux(或者我错过了重点)。

任何帮助,将不胜感激。

4

2 回答 2

2

通过恢复到较旧的编译器解决了该问题。

$ sudo apt-get install g++-4.8
$ g++-4.8 main.cpp -L ~/instantclient_12_2 -locci -lclntsh -I ~/instantclient_12_2/sdk/include

也许最新的编译器和库与用于构建 OCCI 库的那些不兼容。

于 2017-03-19T21:51:12.403 回答
1

如果您使用的是 CMake

1) 在您的 CMakeLists.txt 中添加这一行以指定要使用的编译器

SET(CMAKE_CXX_COMPILER /usr/bin/g++-4.8)

PS你可能需要安装g++-4.8

(apt-get install g++-4.8)
于 2017-08-18T08:24:31.480 回答