2

我正在尝试开发一个两层程序,为此,我需要通过OCCI使用连接池的接口将我的程序连接到数据库(在本例中为 Oracle)。我已经occi.h在 CodeBlocks 中链接了头文件和目录,但是当我尝试编译时,它显示此错误:

|未定义对 `oracle::occi::Environment::createEnvironment(oracle::occi::Environment::Mode, void*, void* ( )(void , unsigned int), void* ( )(void , void* , unsigned int), void ( )(void , void*))'|

||未定义对 `oracle::occi::Environment::terminateEnvironment(oracle::occi::Environment*)'的引用|

||错误:ld 返回 1 个退出状态| ||=== 构建失败:3 个错误,0 个警告(0 分钟,2 秒)===|

有谁明白这个错误是什么意思?我不是 ace C++ 程序员,所以请多多包涵!

这是发生错误的演示代码:

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

class occipool {
  private:
   Environment* env;
   Connection* con;
  Statement* stmt;

 public:
 /**
 * Constructor for the occipool test case.
 */
  occipool() {
    env = Environment::createEnvironment(Environment::DEFAULT);
  }    // end of constructor occipool ()

 /**
* Destructor for the occipool test case.
*/
 ~occipool() {
  Environment::terminateEnvironment(env);
 }    // end of ~occipool ()

 /**
* The testing logic of the test case.
*/
 dvoid select() {
cout << "occipool - Selecting records using ConnectionPool interface"
     << endl;
const string poolUserName = "name";
const string poolPassword = "password";
const string connectString = "name";
const string username = "name";
const string passWord = "password";
unsigned int maxConn = 5;
unsigned int minConn = 3;
unsigned int incrConn = 2;
ConnectionPool* connPool = env->createConnectionPool(
    poolUserName, poolPassword, connectString, minConn, maxConn, incrConn);
try {
  if (connPool)
    cout << "SUCCESS - createConnectionPool" << endl;
  else
    cout << "FAILURE - createConnectionPool" << endl;
  con = connPool->createConnection(username, passWord);
  if (con)
    cout << "SUCCESS - createConnection" << endl;
  else
    cout << "FAILURE - createConnection" << endl;
} catch (SQLException ex) {
  cout << "Exception thrown for createConnectionPool" << endl;
  cout << "Error number: " << ex.getErrorCode() << endl;
  cout << ex.getMessage() << endl;
}

cout << "retrieving the data" << endl;
stmt = con->createStatement("SELECT ID, dept_name FROM p_worker");
ResultSet* rset = stmt->executeQuery();
while (rset->next()) {
  cout << "author_id:" << rset->getInt(1) << endl;
  cout << "author_name:" << rset->getString(2) << endl;
}
stmt->closeResultSet(rset);
con->terminateStatement(stmt);
connPool->terminateConnection(con);
env->terminateConnectionPool(connPool);

cout << "occipool - done" << endl;
}  // end of test (Connection *)

};  // end of class occipool

  int main(void) {
 string user = "name";
 string passwd = "password";
 string db = "name";

 occipool* demo = new occipool();

 demo->select();
 delete demo;

  }  // end of main ()
4

1 回答 1

0

您是否与 libocci.so 和 -libclntsh.so 库链接?

是需要。

于 2018-04-06T20:08:22.360 回答