企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## code ``` #include "mainwindow.h" #include <QApplication> #include <QSqlDatabase> #include <QDebug> #include <QSqlQuery> int main(int argc, char *argv[]) { QApplication a(argc, argv); QStringList drivers = QSqlDatabase::drivers(); foreach(QString driver,drivers){ qDebug()<< "driver "<<driver; // driver "QSQLITE" // driver "QMYSQL" // driver "QMYSQL3" // driver "QPSQL" // driver "QPSQL7" } QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(":memory:"); if(!db.open()){ qDebug()<<"open error"; return 1; } QSqlQuery query; query.exec("create table student(id int primary key,name varchar)"); query.exec("insert into student values(1,'xiaogang')"); query.exec("insert into student values(2,'xiaoming')"); query.exec("insert into student values(3,'xiaohong')"); //查找表中id >=2 的记录的id项和name项的值 query.exec("select id,name from student where id >= 2"); while (query.next()) { int value0 = query.value(0).toInt(); QString value1 =query.value(1).toString(); qDebug()<<"value0,value1 "<<value0,value1; } return a.exec(); } ```