otl 使用

// TODO: 在此处引用程序需要的其他头文件
#define OTL_ODBC 
//OTL连接方式为ODBC
#define OTL_STREAM_READ_ITERATOR_ON 
//使用OTL迭代器
#define OTL_STL 
//OTL使用标准库#include "otlv4.h"
otl_connect db; 
// connect objectotl_connect::otl_initialize(); 
// initialize the database API environment
try
{ 
	std::string str ="DSN=dbsource; UID=sa; PWD=800100;";
	db.rlogon(str.c_str(),1);
	// connect to the database API std::string 
	_sql = "{call CTI_GetATaskItem(:TaskID,:ItemID,:TelNum)}";
	otl_stream os(1,_sql.c_str(),db); os << 13; int tt = -1;
 	char nn[50]= {0}; 
	os >> tt >> nn; 
	cout << tt << "," << nn; 
} 
catch(otl_exception& p)
{ 
	// intercept OTL exceptions cerr<<p.code<<endl;
 	// print out error code cerr<<p.msg<<endl; 
	// print out error message cerr<<p.stm_text<<endl; 
	// print out SQL that caused the error cerr<<p.var_info<<endl;
 	// print out the variable that caused the error 
} 
db.logoff(); 
// disconnect from the database

猜你喜欢

转载自blog.csdn.net/stafniejay/article/details/47404417