Qt remote connection to Oracle Database

Source: Internet
Author: User

I. Code

  1. /** Connect to the Oracle database
  2. * Database Name: abc
  3. * Table Name: my_oracle
  4. * User name: system
  5. * Key: 123
  6. * Port: (default) 1521
  7. */
  8. Void MainDialog: connectOracle (QString sIp, int iPort, QString sDbNm, QString SUSErNm, QString sPwd)
  9. {
  10. Db = QSqlDatabase: addDatabase ("QOCI ");
  11. Db. setHostName (sIp );
  12. Db. setPort (iPort );
  13. Db. setDatabaseName (sDbNm );
  14. Db. setUserName (sUserNm );
  15. Db. setPassword (sPwd );
  16. If (db. open ())
  17. {
  18. QMessageBox: information (this, tr ("prompt"), tr ("Oracle database connection successful! "), Tr (" OK "));
  19. }
  20. Else
  21. {
  22. QMessageBox: information (this, tr ("prompt"), tr ("Oracle database connection failed! "), Tr (" OK "));
  23. QDebug () <"error_Oracle: \ n" <db. lastError (). text ();
  24. }
  25. }

Ii. problems encountered during the connection.

Question 1:

QSqlDatabase: QOCI driver not loaded

QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC
(1) cause of error: the connection is driven by QMYSQL, while Qt itself does not have a QOCI Driver (only QSQLITE QODBC3 QODBC ),

Therefore, you need to compile QOCI by yourself.

(2) Compile the QOCI driver.

1. go to "Qt Command Prompt" window. (START-Program-find the corresponding qt item ).

2. qmake "INCLUDEPATH + = c: \ oracle \ oci \ include" "LIBS + =-Lc: \ oracle \ oci \ lib \ msvc" oci. pro

3. qmake "INCLUDEPATH + = D: \ oracle_setup \ app \ admin \ product \ 11.1.0 \ db_3 \ OCI \ include" "LIBS + =-LD: \ oracle_setup \ app \ admin \ product \ 11.1.0 \ db_3 \ OCI \ lib \ msvc "oci. pro

4. mingw32-make

Question 2:

Error:

D: \ qt_sdk \ qt \ src \ plugins \ sqldrivers \ oci> mingw32-make
Mingw32-make-f Makefile. Debug all
Mingw32-make [1]: Entering directory 'd:/qt_sdk/qt/src/plugins/sqldrivers/oci'
Mingw32-make [1]: Nothing to be done for 'all '.
Mingw32-make [1]: Leaving directory 'd:/qt_sdk/qt/src/plugins/sqldrivers/oci'
Mingw32-make-f Makefile. Release all
Mingw32-make [1]: Entering directory 'd:/qt_sdk/qt/src/plugins/sqldrivers/oci'
Mingw32-make [1]: Nothing to be done for 'all '.
Mingw32-make [1]: Leaving directory 'd:/qt_sdk/qt/src/plugins/sqldrivers/oci'

Cause of error: the QOCI driver has been compiled!

  • 1
  • 2
  • Next Page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.