首先,我们建立一个Dev C++项目,名为“OTL”
在弹出的对话框中选择“Empty Project”
接下来选择一个位置来保存工程文件
之后,我们将向工程中添加我们的源代码文件,源代码文件如下:
#include <iostream>
using namespace std;
#include <stdio.h>
#define OTL_ORA9I // 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("scott/tiger@ORACLE9I "); // connect to Oracle
cout<<"Connect to Database"<<endl;
}
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;
}
我们还需要将otlv4.h这个头文件添加到我们的工程中。
此时,我们需要设置一下头文件的路径和库文件的路径
此时,我们就可以编译并执行该程序了!
作者:http://allanyan.cnblogs.com/articles/105159.html