这些日子被 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的才实现可以登录数据库。代码是网上的范例,难的是这个过程。过程明白了一切就明白了
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;
}
//