#include <iostream>
#include <occi.h>
using namespace std;
int main()
{
Environment *env;
Connection *con;
try
{
env = Environment::createEnvironment (Environment::DEFAULT);
{
con = env->createConnection ("user51","ora123");
Statement *stmt = con->createStatement("SELECT * FROM DUAL");
ResultSet *rs=stmt->executeQuery();
rs->next();
string empname=rs->getString(1);
cout << "Hello Word! of C++ and Oracle database " << empname << endl;
con->terminateStatement(stmt);
env->terminateConnection (con);
}
Environment::terminateEnvironment(env);
}
catch (SQLException e)
{
cout << "Exception thrown" << endl;
cout << "Error number: " << e.getErrorCode() << endl;
cout << e.getMessage() << endl;
}
return 0;
}
Y aqui esta la forma de compilarlo.
g++ -I $ORACLE_HOME/rdbms/public -L $ORACLE_HOME/lib -lclntsh -locci helloword.cpp -o helloword.out
No hay comentarios:
Publicar un comentario