#define OTL_ODBC
#include "otlv4.h"
连接
otl_connect db;
otl_connect::otl_initialize();
db.rlogon("Driver={Microsoft ODBC for Oracle};Server=kmjy;Uid=akai;Pwd=123456;"); //通过ODBC连接ORACLE数据库
简单执行SQL
try{
otl_cursor::direct_exec(db,"select * from a_table");
}
catch (otl_exception& e)
{
CString msg=e.msg;
}
插入语句流
otl_stream o(50,"insert into a_table values (:f1<int>,:f2<char[31]>)",db);
o<<22<<"hello";
查询
otl_stream o(100,"select * from a_test",db);
while(!o.eof())
{
int id;
char name[20];
otl_datetime t;
o>>id>>name>>t;
CString str;
str.Format("id=%d,name=%s,时间=%d-%d-%d %d:%d:%d",id,name,t.year,t.month,t.day,t.hour,t.minute,t.second);
}
db.logoff(); //关闭数据库

本文介绍使用OTL库通过ODBC连接Oracle数据库的方法,并演示了基本的SQL执行、数据插入及查询操作。
423

被折叠的 条评论
为什么被折叠?



