Home > Blockchain >  How to connect to oracle cloud database from Qt5
How to connect to oracle cloud database from Qt5

Time:05-09

Can someone help me with the connection to the Oracle Cloud from Qt.

I can't find any information on the Qt website, nor examples, but surely someone has wanted to connect to an instance of autonomous data base, with Qt.

I already connect with SqlDeveloper, with SqlCl, I just need to be able to do it with Qt, because I can't find the way

Thank you very much !

CodePudding user response:

Assuming that your code base is a client server application written in C , you would probably want to use occi to natively access your Oracle Database.

CodePudding user response:

I finally managed to get it working. The code is the following:

extern int      QtConnection(int argc, char *argv[])
{
    QCoreApplication a();
    
    QSqlDatabase db = QSqlDatabase::addDatabase("QOCI", "conn_name"); 
    
    db.setDatabaseName("database");
    db.setUserName("eternumx");
    db.setPassword("12345678");
    db.setConnectOptions("OCI_ATTR_PREFETCH_ROWS=1000"); 

    if (db.isValid())
    {   
        db.open();

        if (!db.isOpen())
        {   
            qDebug() << db.lastError().text().toLatin1().data() << endl;
            return 0;
        }   
    }   
    else
    {   
        qDebug() << db.lastError().text().toLatin1().data() << endl;
        return 0;
    }   

    return 1;
}

Then configure the environment variables TNS_ADMIN (for which the program finds the sqlnet.ora and tnsnames.ora files) and the sqlnet.ora file that indicates where the wallet is. worked perfectly

  • Related