if (!db.open()) { QMessageBox::critical(0, qApp->tr("Cannot open database"), qApp->tr("Unable to establish a database connection.\n" "This example needs QODBC support. Please read " "the Qt SQL driver documentation for information how " "to build it.\n\n" "Click Cancel to e...
QMessageBox::critical(0, qApp->tr("Cannot open database"), qApp->tr("Unable to establisha database connection." ), QMessageBox::Cancel); return false; } QSqlQuery query; query.exec("create table student (id int primary key, " "name varchar(20))"); query.exec("insert into student...
QSqlDatabase db1 = QSqlDatabase::addDatabase("QSQLITE"); //db1.setDatabaseName(":memory:"); /* 表明是建立在内存中的数据库 */ db1.setDatabaseName("my1.db"); if (!db1.open()) { QMessageBox::critical(0, "Cannot open database", "Unable to establish a database connection."...
qApp->tr("Unable to establisha database connection."),QMessageBox::Cancel);returnfalse;} QSqlQu...
"Unabletoestablishadatabaseconnection.",QMessageBox::Cancel); returnfalse; } else{ QMessageBox::critical(0,"congratulation!","oracledatabaseconnnectsuccessfuly!!!",QMessageBox::Ok); returntrue; } } 运行结果如下: 说明数据库已连接成功!!!
db.setDatabaseName("maindb.db"); //如果是内存数据库,就用db.setDatabaseName(":memory:"); //连接失败的提示 if (!db.open()) { QMessageBox::critical(0, qApp->tr("Cannot open database"), qApp->tr("Unable to establish a database connection.\n" ...
//打开数据库 QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");db.setDatabaseName("nmr.db");if (!db.open()){ QMessageBox::critical(0, qApp->tr("Cannot open database"),qApp->tr("Unable to establish a database connection.\n""This example needs SQLite support. ...
Unabletoestablishadatabaseconnection.\n ThisexampleneedsSQLitesupport.Pleaseread theQtSQLdriverdocumentationforinformationhow tobuildit.\n\n ClickCanceltoexit.,QMessageBox::Cancel); return; } QSqlQueryquery; query.exec(CREATETABLEIFNOTEXISTSperson(idINTEGERPRIMARY ...
"Unable to establish a database connection.", QMessageBox::Cancel); 1. return false; 1. } 1. else{ 1. QMessageBox::critical(0,"congratulation!","oracle database connnect successfuly!!!",QMessageBox::Ok); 1. return true; 1. ...