天天看點

vc2005 操作oracle10g

這些日子被 oracle整得快不行了。又是proC,proC的檔案簡直和密碼一樣,偏偏裝了10g,結果調試啥的非常不友善,建議要是程式設計的話還是9i的為好。

又要求用otl連接配接資料庫。搞了半天,才曉得在 工具-選項-VC++目錄—引用檔案添加入"D:\oracle\product\10.2.0\db_1\OCI\lib\MSVC" ---oci.lib(這裡我把oci.lib給弄出來,硬是不行,怪了)。同時也要找到安裝目錄下的ori.h。同樣的指引過去。

到這個時候。我tmd的才實作可以登入資料庫。代碼是網上的範例,難的是這個過程。過程明白了一切就明白了

vc2005 操作oracle10g
vc2005 操作oracle10g

Code

#include <iostream> 

using namespace std; 

#include <stdio.h> 

//下面這個和你的資料庫版本一緻,同時otl4.h中也要把部分注釋掉的取消才行

#define OTL_ORA10G_R2 // Compile OTL 4.0/OCI9i 

#define OTL_ORA_TIMESTAMP // enable Oracle 9i TIMESTAMPs [with [local] time zone] 

#include "otlv4.h" // include the OTL 4.0 header file 

otl_connect db; // connect object 

int main() 

    otl_connect::otl_initialize(); // initialize OCI environment  

    try 

    { 

        db.rlogon("mzzbs/mzzbsadmin@ORA_TEST_16"); // connect to Oracle  

        cout<<"Connect to Database"<<endl; 

        getchar();

    } 

    catch(otl_exception& p) 

    {  

        // intercept OTL exceptions  

        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  

    db.logoff(); // disconnect from Oracle 

    return 0; 

//