Results 1 to 4 of 4

Thread: How connect to Oracle DB

  1. #1
    Join Date
    Feb 2007
    Posts
    71
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default How connect to Oracle DB

    How connect to Oracle DB

    do you have some code show me?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How connect to Oracle DB

    Check out QSqlDatabase.

    Note that Oracle driver is available for commercial Qt.

  3. #3
    Join Date
    Jan 2006
    Location
    Lincoln, NE USA
    Posts
    177
    Thanks
    3
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How connect to Oracle DB

    Depends on your DBHOST name and DBNAME.
    Here is part of main.cpp:
    Qt Code:
    1. #ifdef _WIN32 // on Windows
    2. #define DBDRIVER "QOCI"
    3. #define DBHOST "orc1"
    4. #define DBNAME "orc1"
    5. #else // must be on Linux and PostgreSQL 8
    6. #define DBDRIVER "QPSQL"
    7. #define DBHOST "localhost"
    8. #define DBNAME "homestead"
    9. #endif
    10.  
    11. int main( int argc, char * argv[] ) {
    12. ...
    13. QString strRejected = "";
    14. QApplication app(argc, argv);
    15. app.setQuitOnLastWindowClosed(false);
    16. dlgLogin dlg; // gets name and password from login dialog
    17. if( dlg.exec() == QDialog::Accepted ){
    18. QSqlDatabase hapdb = QSqlDatabase::addDatabase(DBDRIVER);
    19. hapdb.setHostName(DBHOST);
    20. hapdb.setDatabaseName(DBNAME);
    21. hapdb.setUserName(dlg.dui.leUserName->text());
    22. hapdb.setPassword(dlg.dui.leUserPassword->text());
    23. if ( hapdb.open() ) {
    24. homestead ht;
    25. ht.RevID = dlg.dui.leUserName->text();
    26. ht.show();
    27. app.setQuitOnLastWindowClosed(true);
    28. return app.exec();
    29. } else {
    30. strRejected = QString("Reason: %1").arg(hapdb.lastError().text()).toLatin1();
    31. QMessageBox::information(0,"Login Rejected!",strRejected,
    32. QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
    33. return 1;
    34. }
    35. } else {
    36. strRejected = QString("User Canceled the login!").toLatin1();
    37. QMessageBox::information(0,"Login Canceled!",strRejected,
    38. QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
    39. return 2;
    40. }
    41. }
    To copy to clipboard, switch view to plain text mode 
    Now, because hapdb is the default database in the application, any queries, etc. are against that database, so it does not have to be referenced. For more than one db open at the same time consult the Qt Assistant.

    In the app init code:
    Qt Code:
    1. // create query string that selects for proprty_id in property table
    2. this->propPIDqryStr = "SELECT proprty_id, county, cntyname, txdistrict, legal, ";
    3. this->propPIDqryStr.append("parcel_id, pvalue, pctext, totincome, entry_id, entry_date, ");
    4. this->propPIDqryStr.append("appstatus, offuse, itotinc, ivalue, ipctex, notes FROM ");
    5. this->propPIDqryStr.append(this->propertydb);
    6. this->propPIDqryStr.append(" WHERE proprty_id = ");
    To copy to clipboard, switch view to plain text mode 
    In a search function:
    Qt Code:
    1. if (ui.rbProprtyID->isChecked()) {
    2. // user is searching for property id
    3. requestString.append(" in Property");
    4. ui.leStatus->setText(requestString);
    5. propStr = this->propPIDqryStr;
    6. propStr.append(ui.leSearch->text());
    7. propQry->exec(propStr);
    8. if (propQry->first()){
    9. // found property record, now fetch associated persinfo record
    10. foundProp = true;
    11. persStr = this->persPIDqryStr;
    12. persStr.append(ui.leSearch->text());
    13. persQry->exec(persStr);
    14. if (persQry->first()) {
    15. foundPers = true;
    16. }
    17. }
    18. } // end proprty_id
    To copy to clipboard, switch view to plain text mode 
    Other code retrieves the data from propQry and persQry and displays it.

  4. #4
    Join Date
    Feb 2007
    Posts
    71
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How connect to Oracle DB

    Thanks every one ~ I think this some good tip~ go on

Similar Threads

  1. Oracle 8.0
    By magikalpnoi in forum Qt Programming
    Replies: 2
    Last Post: 29th September 2006, 05:47
  2. Replies: 5
    Last Post: 28th August 2006, 14:36
  3. Fix: QT app won't run under Oracle Standard Client install
    By GreyGeek in forum General Discussion
    Replies: 0
    Last Post: 12th May 2006, 18:20
  4. connect
    By mickey in forum Newbie
    Replies: 1
    Last Post: 25th February 2006, 18:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.