首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++如何连接oracle数据库

2012-05-04 
C++怎么连接oracle数据库我需要用C++连接oracle数据库,有哪位高人能指点一下,我只需要连接成功,完成基本的

C++怎么连接oracle数据库
我需要用C++连接oracle数据库,有哪位高人能指点一下,我只需要连接成功,完成基本的查询信息就好了。
数据库是oracle9i,数据库名:shensuoyao,数据库表:shensuoyao,字段:name varchar2(10),age number
数据库用户名 ssy,密码:ssy
不管用什么方法,能连上oracle就好。
最好给出代码,用VC++6.0或者VS2008或VS2005编写,需要写出详细的配置。


[解决办法]
试试下面的OTL代码,其中otlv4.h需要下载,oci.lib及oci.h(otlv4.h中需要)在Oracle安装时候已经提供

C/C++ code
#define OTL_ORA9I#include <fstream>#include <iostream>#include <windows.h>#include "otlv4.h"using namespace std;#pragma comment(lib,"oci.lib")void select();otl_connect db;int main(int argc,char *argv[]){    try{        otl_connect::otl_initialize();     //初始化OTL环境,1表示支持多线程        db.rlogon("ssy/ssy@shensuoyao");   //调用rlogon()函数连接到数据库        db.auto_commit_off();              //关闭自动提交        cout<<"连接数据库成功!"<<endl;    }catch(otl_exception& p){                // 处理OTL异常        cerr<<p.msg<<endl;                    // 打印错误信息        cerr<<p.stm_text<<endl;            // 打印导致出错的SQL        cerr<<p.sqlstate<<endl;            // print out SQLSTATE message        cerr<<p.var_info<<endl;            // print out the variable that caused the error    }        select();    db.commit ( );    db.logoff();    system("pause");    return 0;    }void select(){     try{        otl_stream i(50,            "select f1, f2 from shensuoyao",                    db            );         char f1[11];               int f2;                while(!i.eof()){             i>>f1>>f2;            cout<<"姓名:"<<f1<<" 学号:"<<f2<<endl;                            }                }    catch(otl_exception& p)     {                           cerr<<p.msg<<endl; // print out error message          cerr<<p.stm_text<<endl; // print out SQL that caused the error          cerr<<p.sqlstate<<endl; // print out SQLSTATE message          cerr<<p.var_info<<endl; // print out the variable that caused the error              } } 

热点排行