#include <iostream>
#include <stdio.h>
#include <cstring>
#include <occi.h>using namespace std;
using namespace oracle::occi;int main() {
Environment *env = Environment::createEnvironment();//初始化occi环境 // 用户输入密码,名字,数据库
string name;
string pwd;
string dbname;
cout<<"请输入用户名,密码及数据库连接串:"<<endl;
cin>>name>>pwd>>dbname;
Connection *conn=env->createConnection(name,pwd,dbname);//创建到oracle的连接
cout<<"您已成功连接数据库!"<<endl; string strQuery("select * from emp"); Statement *stmt=conn->createStatement(strQuery);//创建查询语句 ResultSet *rs;//创建记录集用于返回查询的结果
rs=stmt->executeQuery();//执行查询语句 string strTemp;//存储记录中的数据 //next用于从记录集中获取下一行数据
while (rs->next()==true)
{
strTemp=rs->getString(2);
cout<<strTemp<<endl;
} stmt->closeResultSet(rs);//关闭记录集
conn->terminateStatement(stmt);//关闭语句 env->terminateConnection(conn);//关闭连接 Environment::terminateEnvironment(env);//关闭环境
return 0;}

D:\ddtech\eclipse\OCCI\Debug/../src/main.cpp:12: undefined reference to `oracle::occi::Environment::createEnvironment(oracle::occi::Environment::Mode, void*, void* (*)(void*, unsigned int), void* (*)(void*, void*, unsigned int), void (*)(void*, void*))'
D:\ddtech\eclipse\OCCI\Debug/../src/main.cpp:48: undefined reference to `oracle::occi::Environment::terminateEnvironment(oracle::occi::Environment*)'
环境:windows xp 32bit + eclipse cdt (gcc 4.4.1)
oracle 11g : 
D:\app\Administrator\product\11.1.0\db_1\OCI\lib\MSVC 目录下kpucb.lib,oci.lib,ociw32.lib,oraocci11.lib这个问题找了一下午都没解决,感觉是库文件的问题occi.lib和clntsh.lib, 找不到这两个文件。

解决方案 »

  1.   

    1.There is no OCCI library compiled for GNU g++ on a Windows host.You have to use Microsoft Visual Studio. 2.Cygwin supports the usage of shared libraries, the extension under Microsoft Windows is .dll; The libclntsh.a is named oci.lib under Windows.http://cn.forums.oracle.com/forums/thread.jspa?threadID=527946感觉还是库文件的问题