簡單使用OTL進行數據庫編程

#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();  //關閉數據庫

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章