Documents > BPS V2 C++ API
database1.cpp

This is a basic database sample. It creates a connection to a oracle database, queries the users and disconnects again.

#include <bpsexception.h>
#include <bpsdatastore.h>
#include <QCoreApplication>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    try {
        qDebug() << "create datastore object";
        BpsDatastore ds;

        qDebug() << "connect to database";
        ds.setDriver("QOCI");               // Oracle driver
        ds.setDatabase("jupiter");          // TNS name
        ds.setUsername("scott");            // user name
        ds.setPassword("tiger");            // user password
        ds.connect();

        qDebug() << "list the database users";
        qDebug() << ds.users();

        qDebug() << "disconnect from database";
        // Basically this disconnect is obsolete, because when ds gets out
        // of scope at the end of this C++ block, the destructor will 
        // do a disconnect
        ds.disconnect();
    } // try
    catch (const BpsException& exc) {
        // in case anything went wrong, show the error messages
        qDebug() << exc.text();
    } // catch
} // main
 All Classes Files Functions Typedefs Enumerations Enumerator Friends Defines