connecting a c++ application to an Oracle database with sqlapi++

592 Views Asked by At

I wrote an example application in C++(on Eclipse Luna) using sqlapi++ libraries to connect to an Oracle database I created with sqldeveloper. The program compiles without errors, but when I run it,nothing appears on the console.

(I am using Windows 7)

Here the Database information:
Database name:"DB Casa Editrice"
Host:localhost
SID:xe
Port:1521

And the code:

#include <iostream>
#include "SQLAPI.h"
using namespace std;

int main() {
    SAConnection con; // create connection object

    try {
        con.Connect( "DB Casa Editrice",     // database name
                     "system",   // user name
                     "shruikan94",   // password
                     SA_Oracle_Client );

        cout << "We are connected!\n";
        con.Disconnect();
        cout << "Disconnected!\n";
    }
    catch( SAException &x )
    {
        // SAConnection::Rollback()
        // can also throw an exception
        // (if a network error for example),
        // we will be ready
        try {
            // on error rollback changes
            con.Rollback();
        }
        catch( SAException & )
        {
        }
        // print error message
        cout << "ERROR\n";
    }
    return 0;
}
0

There are 0 best solutions below