⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex365_odbc.cpp

📁 一个跨平台的数据库操作库文件,可以轻松在linux和windows下进行数据库读写以及其他的操作,支持多种数据库,代码包含很多example,初学者很容易上手. OTL 是 Oracle, Odbc
💻 CPP
字号:
// One of the following two #define's enables ODBC / DB2 CLI 
// Unicode SQLxxxW functions
#define UNICODE
#define _UNICODE

#include <iostream>
using namespace std;

#include <stdio.h>

#define OTL_ODBC_MSSQL_2005 // Compile OTL 4/ODBC, MS SQL 2005
//#define OTL_ODBC // Compile OTL 4/ODBC. Uncomment this when used with MS SQL 7.0/ 2000
#define OTL_UNICODE // Enable Unicode OTL for ODBC

// Enable OTL Unicode rlogon and otl_exception for ODBC
#define OTL_UNICODE_EXCEPTION_AND_RLOGON 

#if defined(__GNUC__)
#define OTL_UNICODE_CHAR_TYPE SQLWCHAR
#else
#define OTL_UNICODE_CHAR_TYPE wchar_t
#endif

#include <otlv4.h> // include the OTL 4.0 header file

otl_connect db; // connect object

int main()
{
 otl_connect::otl_initialize(); // initialize the database API environment
 try{
// Special Unicode rlogon function
  db.rlogon(L"scott",
            L"tiger",
            L"mssqlxxx"
           ); // connect to the database

 }

 catch(otl_exception& p){ // intercept OTL exceptions
#if defined(__GNUC__)
  OTL_UNICODE_CHAR_TYPE* c=p.msg;
  while(*c){
    cerr<<static_cast<char>(*c);
    ++c;
  }
  cerr<<endl;
  c=p.sqlstate;
  while(*c){
    cerr<<(char)*c;
    ++c;
  }
  cerr<<endl;
#else
  wcerr<<p.msg<<endl; // print out error message
  wcerr<<p.sqlstate<<endl; // print out error sqlstate
  wcerr<<p.stm_text<<endl; // print out SQL that caused the error
  wcerr<<p.var_info<<endl; // print out the variable that caused the error
#endif
 }

 db.logoff(); // disconnect from the database

 return 0;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -