Archive for 3月 31st, 2012
-
Hello, OCCI World!
Posted on 3月 31st, 2012 by cx20
OCCI
OCCI(Oracle C++ Call Interface)は Oracle Database 用の C++ API である。
ソースコード
#include <iostream> #include <occi.h> using namespace std; using namespace oracle::occi; int main( int argc, char* argv[] ) { Environment* env = Environment::createEnvironment(); Connection* con = env->createConnection("scott", "tiger", "orcl"); Statement* stmt = con->createStatement("SELECT 'Hello, OCCI World!' AS Message FROM DUAL"); ResultSet* rs = stmt->executeQuery(); while( rs->next() ) { cout << rs->getString(1) << endl; } stmt->closeResultSet(rs); con->terminateStatement(stmt); env->terminateConnection(con); Environment::terminateEnvironment(env); return 0; }
コンパイル&リンク方法(Visua C++)
C:¥> SET INCLUDE=ORACLE_BASEORACLE_HOMEociinclude;%INCLUDE% C:¥> SET LIB=ORACLE_BASEORACLE_HOMEocilibmsvc;%LIB% C:¥> cl hello.cpp /link oraocci11.lib
実行結果
Hello, OCCI World!