C/C++ code#include
#include
#include
#include
#include
int main(int argc,char *argv[])
{
QCoreApplication a(argc,argv);
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForLocale(codec);
QTextCodec::setCodecForCStrings(codec);
QTextCodec::setCodecForTr(codec);
QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("project");
db.setUserName("root");
db.setPassword("0");
if(db.open())
{
qDebug()<
}
else
{
qDebug()<
return a.exec();
}
QSqlQuery query;
query.exec(QObject::tr("select * from student"));
QSqlRecord rec=query.record();
int count=rec.count();
qDebug()<
while(query.next())
{
rec=query.record();
int name=rec.indexOf("name");
int card=rec.indexOf("card");
int user=rec.indexOf("user");
int password=rec.indexOf("password");
int book =rec.indexOf("book");
QString value1 =query.value(name).toString();
QString value2 =query.value(card).toString();
QString value3 =query.value(user).toString();
QString value4 =query.value(password).toString();
QString value5 =query.value(book).toString();
qDebug()<
<
}
query.clear();
db.close();
return a.exec();
}