Skip to content

Instantly share code, notes, and snippets.

@0xlitf
Created March 7, 2016 06:55
Show Gist options
  • Save 0xlitf/baede69a2edc522009dc to your computer and use it in GitHub Desktop.
Save 0xlitf/baede69a2edc522009dc to your computer and use it in GitHub Desktop.
64位oracle驱动.cpp
#include "mainwindow.h"
#include <QApplication>
#include <QtGui>
#include <QtSql>
int main(int argc, char **argv)
{
QApplication myApp(argc, argv);
QLibrary *hello_lib = NULL;
//写清楚库的路径,如果放在当前工程的目录下,路径为./Oracle.so
hello_lib = new QLibrary("C:\\Oracle\\product\\11.2.0\\client_1\\BIN\\oci.dll");
//hello_lib = new QLibrary("C:\\Qt\\Qt5.5.1\\5.5\\msvc2013\\plugins\\sqldrivers\\qsqlocid.dll");
//hello_lib = new QLibrary("E:\\CPPProject\\OracleTest\\Debug\\qsqlocid.dll");
//hello_lib = new QLibrary("E:\\CPPProject\\OracleTest\\Release\\qsqlocid.dll");
//加载动态库
hello_lib->load();
if (!hello_lib->isLoaded())
{
qDebug("load Oracle failed!\n");
}
else
{
qDebug("load Oracle success!\n");
}
qDebug() << "Available drivers:";
QStringList drivers = QSqlDatabase::drivers();
foreach(QString driver, drivers)
qDebug() << "\t" << driver;
QSqlDatabase dbTest = QSqlDatabase::addDatabase("QOCI");
qDebug() << "QOCI driver valid?" << dbTest.isValid();
// QSqlDatabase db;
// db.addDatabase("QOCI");
// db.setDatabaseName("orcl");
// db.setUserName("system");
// db.setPassword("huiyi");
// db.setPort(1521);
return myApp.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment